﻿using BLL.Base;
using CommandService;
using Entity;
using Entity.DbEntity;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Hosting;
using Tools;

namespace BLL.Basis
{
    /// <summary>
    /// 生产配置业务逻辑层
    /// </summary>
    public class ProductSetBLL : PubMethod
    {
        Commands cmd;
        LoginInfo userLogin;
        List<OperateModel> operList;
        OperateModel oper;
        ReturnResult rsl;
        StringBuilder sb = new StringBuilder();
        //TxtLogHelper txt;
        public ProductSetBLL()
        {
            //数据交互
            cmd = new Commands();
            //当前登录人信息
            userLogin = new LoginInfo();
            //txt = new TxtLogHelper();
        }
        /// <summary>
        /// 保存品类生产工艺
        /// </summary>
        /// <param name="datas">选择的生产工艺</param>
        /// <param name="proType">工艺编码</param>
        /// <returns></returns>
        public ReturnResult SaveProGongYi(string datas, string proType)
        {
            rsl = new ReturnResult();
            operList = new List<OperateModel>();
            try
            {
                StringBuilder sb = new StringBuilder();
                ProductsGongXu pgx;
                if (string.IsNullOrWhiteSpace(datas))
                {
                    rsl.Message = "配置任何生产工艺";
                    return rsl;
                }
                sb.Append("select * from fun_Products_gx where proCode='" + proType + "'");
                var pgxTable = cmd.GetDataTable(sb.ToString());//已有存货工艺
                sb.Clear();
                sb.Append("select g.* from fun_GxPrice_info g ");
                sb.Append(" where g.proType='" + proType + "'");
                var gxTable = cmd.GetDataTable(sb.ToString());

                sb.Clear();
                sb.Append("select * from  fun_CommonData_Info where cType='gx' and isdel=0");
                var fTable = cmd.GetDataTable(sb.ToString());
                var cArr = datas.Split(',');
                List<Dictionary<string, string>> xhList = new List<Dictionary<string, string>>();
                #region 添加
                for (int i = 0; i < cArr.Length; i++)
                {
                    if (!string.IsNullOrWhiteSpace(cArr[i]))
                    {
                        var dr = fTable.Select("cCode='" + cArr[i] + "'");//判断是否是父节点工序
                        if (dr.Length > 0)
                        {
                            saveGXXH(cArr[i], dr[0]["orderNum"].ToString(), ref xhList);
                        }
                        #region 判断生产工序是否是有子工序，有子工序的工序编码系统不保存
                        dr = gxTable.Select("gxCode='" + cArr[i].Trim() + "'");
                        if (dr.Length > 0)
                        {//节点下哟子工序，则该节点跳过
                            continue;
                        }
                        dr = gxTable.Select("cgxCode='" + cArr[i].Trim() + "'");//验证是否是子工序
                        string fgxCode = "";//子工序父节点
                        int isChild = 0;
                        if (dr.Length > 0)
                        {
                            isChild = 1;
                            fgxCode = dr[0]["gxCode"].ToString();
                            var fdr = fTable.Select("cCode='" + fgxCode + "'");
                            if (fdr.Length > 0)
                            {
                                saveGXXH(fgxCode, fdr[0]["orderNum"].ToString(), ref xhList);
                            }
                        }
                        #endregion
                        dr = pgxTable.Select("gxCode='" + cArr[i].Trim() + "'");//工艺是否已存在
                        if (dr.Length < 1)
                        {
                            #region 添加数据方法
                            pgx = new ProductsGongXu();
                            oper = new OperateModel();
                            if (!string.IsNullOrWhiteSpace(fgxCode))
                            {
                                for (int y = 0; y < xhList.Count; y++)
                                {
                                    if (xhList[y]["gxCode"] == fgxCode)
                                    {
                                        xhList[y]["number"] = (double.Parse(xhList[y]["number"]) + 1).ToString();
                                        pgx.gxOrder = (double.Parse(xhList[y]["gxNum"]) + double.Parse(xhList[y]["number"]) / 1000).ToString();
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                pgx.gxOrder = "-9999";
                            }

                            pgx.gxCode = cArr[i].Trim();
                            pgx.proCode = proType;
                            pgx.dType = "pType";
                            pgx.isChild = isChild;
                            pgx.createtime = getNow();
                            pgx.createuser = userLogin.UserInfo().userCode;
                            oper.Types = OperateModel.OperateType.Add;
                            oper.Data = pgx;
                            operList.Add(oper);
                            #endregion
                        }
                        else
                        {
                            pgx = new ProductsGongXu();
                            oper = new OperateModel();
                            pgx.id = int.Parse(dr[0]["id"].ToString());
                            if (!string.IsNullOrWhiteSpace(fgxCode))
                            {
                                for (int y = 0; y < xhList.Count; y++)
                                {
                                    if (xhList[y]["gxCode"] == fgxCode)
                                    {
                                        xhList[y]["number"] = (double.Parse(xhList[y]["number"]) + 1).ToString();
                                        pgx.gxOrder = (double.Parse(xhList[y]["gxNum"]) + double.Parse(xhList[y]["number"]) / 1000).ToString();
                                        break;
                                    }
                                }
                            }
                            oper.Data = pgx;
                            oper.Types = OperateModel.OperateType.Edit;
                            oper.Conditions = "id";
                            operList.Add(oper);
                        }
                    }
                }
                #endregion

                #region 删除
                foreach (DataRow r in pgxTable.Rows)
                {
                    string gxCode = r["gxCode"].ToString();
                    bool isDel = true;
                    foreach (string gStr in cArr)
                    {
                        if (gStr == gxCode)
                        {
                            #region   如果是父工艺 且勾选了其子工艺  删除父工艺
                            if (r["isChild"].ToString().Equals("0"))
                            {
                                var dr = gxTable.Select("gxCode='" + gxCode + "'");
                                if (dr.Length > 0)
                                {
                                    break;
                                }
                            }
                            #endregion
                            isDel = false;
                            break;
                        }
                    }
                    if (isDel)
                    {
                        pgx = new ProductsGongXu();
                        pgx.id = int.Parse(r["id"].ToString());
                        oper = new OperateModel();
                        oper.Data = pgx;
                        oper.Types = OperateModel.OperateType.Delete;
                        operList.Add(oper);
                    }
                }
                #endregion

                if (operList.Count > 0)
                {
                    rsl = cmd.MoreUpdate(operList);
                }

            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 保存生产工艺
        /// </summary>
        /// <param name="datas"></param>
        /// <param name="proType"></param>
        /// <param name="gyCode"></param>
        /// <returns></returns>
        public ReturnResult SaveProGongYi_New(string datas, string proType, string gyCode)
        {
            rsl = new ReturnResult();
            operList = new List<OperateModel>();
            try
            {
                StringBuilder sb = new StringBuilder();
                ProductsGongXu pgx;
                if (string.IsNullOrWhiteSpace(datas))
                {
                    rsl.Message = "配置任何生产工艺";
                    return rsl;
                }
                sb.Append("select * from fun_Products_gx where 1=1");
                if (!string.IsNullOrWhiteSpace(gyCode))
                {
                    sb.Append(" and gyCode='" + gyCode + "'");
                }
                else
                {
                    sb.Append(" and proCode='" + proType + "'");
                }
                var pgxTable = cmd.GetDataTable(sb.ToString());//已有存货工艺
                sb.Clear();
                sb.Append("select g.* from fun_GxPrice_info g ");
                sb.Append(" where g.proType='" + proType + "'");
                var gxTable = cmd.GetDataTable(sb.ToString());

                sb.Clear();
                sb.Append("select * from  fun_CommonData_Info where cType='gx' and isdel=0");
                var fTable = cmd.GetDataTable(sb.ToString());
                var cArr = datas.Split(',');
                List<Dictionary<string, string>> xhList = new List<Dictionary<string, string>>();


                #region 添加和修改

                var temgyCode = "GY" + DateTime.Now.ToString("yyyyMMddHHmmss");
                for (int i = 0; i < cArr.Length; i++)
                {
                    if (!string.IsNullOrWhiteSpace(cArr[i]))
                    {
                        var dr = fTable.Select("cCode='" + cArr[i] + "'");//判断是否是父节点工序
                        if (dr.Length > 0)
                        {
                            saveGXXH(cArr[i], dr[0]["orderNum"].ToString(), ref xhList);
                        }
                        #region 判断生产工序是否是有子工序，有子工序的工序编码系统不保存
                        dr = gxTable.Select("gxCode='" + cArr[i].Trim() + "'");
                        if (dr.Length > 0)
                        {//节点下哟子工序，则该节点跳过
                            continue;
                        }
                        dr = gxTable.Select("cgxCode='" + cArr[i].Trim() + "'");//验证是否是子工序
                        string fgxCode = "";//子工序父节点
                        int isChild = 0;
                        if (dr.Length > 0)
                        {
                            isChild = 1;
                            fgxCode = dr[0]["gxCode"].ToString();
                            var fdr = fTable.Select("cCode='" + fgxCode + "'");
                            if (fdr.Length > 0)
                            {
                                saveGXXH(fgxCode, fdr[0]["orderNum"].ToString(), ref xhList);
                            }
                        }
                        #endregion

                        if (string.IsNullOrWhiteSpace(gyCode))
                        {
                            #region 添加数据方法
                            pgx = new ProductsGongXu();
                            oper = new OperateModel();
                            if (!string.IsNullOrWhiteSpace(fgxCode))
                            {
                                for (int y = 0; y < xhList.Count; y++)
                                {
                                    if (xhList[y]["gxCode"] == fgxCode)
                                    {
                                        xhList[y]["number"] = (double.Parse(xhList[y]["number"]) + 1).ToString();
                                        pgx.gxOrder = (double.Parse(xhList[y]["gxNum"]) + double.Parse(xhList[y]["number"]) / 1000).ToString();
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                pgx.gxOrder = "-9999";
                            }
                            pgx.gyCode = temgyCode;
                            pgx.gyName = temgyCode;
                            pgx.gxCode = cArr[i].Trim();
                            pgx.proCode = proType;
                            pgx.dType = "pType";
                            pgx.isChild = isChild;

                            pgx.createtime = getNow();
                            pgx.createuser = userLogin.UserInfo().userCode;
                            oper.Types = OperateModel.OperateType.Add;
                            oper.Data = pgx;
                            operList.Add(oper);
                            #endregion
                        }
                        else
                        {
                            #region 修改数据的方法
                            dr = pgxTable.Select("gxCode='" + cArr[i].Trim() + "'");//工艺是否已存在
                            if (dr.Length < 1)
                            {
                                #region 添加数据方法
                                pgx = new ProductsGongXu();
                                oper = new OperateModel();
                                if (!string.IsNullOrWhiteSpace(fgxCode))
                                {
                                    for (int y = 0; y < xhList.Count; y++)
                                    {
                                        if (xhList[y]["gxCode"] == fgxCode)
                                        {
                                            xhList[y]["number"] = (double.Parse(xhList[y]["number"]) + 1).ToString();
                                            pgx.gxOrder = (double.Parse(xhList[y]["gxNum"]) + double.Parse(xhList[y]["number"]) / 1000).ToString();
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    pgx.gxOrder = "-9999";
                                }
                                //if (string.IsNullOrWhiteSpace(gyCode))
                                //{
                                //    pgx.gyCode = "GY" + DateTime.Now.ToString("yyyyMMddHHmmss");
                                //    pgx.gyName = "GY" + DateTime.Now.ToString("yyyyMMddHHmmss");
                                //}
                                //else
                                //{
                                pgx.gyCode = gyCode;
                                pgx.gyName = pgxTable.Rows[0]["gyName"].ToString();
                                //}
                                pgx.gxCode = cArr[i].Trim();
                                pgx.proCode = proType;
                                pgx.dType = "pType";
                                pgx.isChild = isChild;

                                pgx.createtime = getNow();
                                pgx.createuser = userLogin.UserInfo().userCode;
                                oper.Types = OperateModel.OperateType.Add;
                                oper.Data = pgx;
                                operList.Add(oper);
                                #endregion
                            }
                            else
                            {

                                if (!string.IsNullOrWhiteSpace(fgxCode))
                                {
                                    pgx = new ProductsGongXu();
                                    oper = new OperateModel();
                                    pgx.id = int.Parse(dr[0]["id"].ToString());
                                    for (int y = 0; y < xhList.Count; y++)
                                    {
                                        if (xhList[y]["gxCode"] == fgxCode)
                                        {
                                            xhList[y]["number"] = (double.Parse(xhList[y]["number"]) + 1).ToString();
                                            pgx.gxOrder = (double.Parse(xhList[y]["gxNum"]) + double.Parse(xhList[y]["number"]) / 1000).ToString();
                                            break;
                                        }
                                    }
                                    oper.Data = pgx;
                                    oper.Types = OperateModel.OperateType.Edit;
                                    oper.Conditions = "id";
                                    operList.Add(oper);
                                }

                            }
                            #endregion
                        }
                    }
                }
                #endregion

                #region 删除
                if (!string.IsNullOrWhiteSpace(gyCode))
                {
                    foreach (DataRow r in pgxTable.Rows)
                    {
                        string gxCode = r["gxCode"].ToString();
                        bool isDel = true;
                        foreach (string gStr in cArr)
                        {
                            if (gStr == gxCode)
                            {
                                #region   如果是父工艺 且勾选了其子工艺  删除父工艺
                                if (r["isChild"].ToString().Equals("0"))
                                {
                                    var dr = gxTable.Select("gxCode='" + gxCode + "'");
                                    if (dr.Length > 0)
                                    {
                                        break;
                                    }
                                }
                                #endregion
                                isDel = false;
                                break;
                            }
                        }
                        if (isDel)
                        {
                            pgx = new ProductsGongXu();
                            pgx.id = int.Parse(r["id"].ToString());
                            oper = new OperateModel();
                            oper.Data = pgx;
                            oper.Types = OperateModel.OperateType.Delete;
                            operList.Add(oper);
                        }
                    }
                }
                #endregion

                if (operList.Count > 0)
                {
                    rsl = cmd.MoreUpdate(operList);
                }

            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 删除工艺数据
        /// </summary>
        /// <param name="gyCode"></param>
        /// <returns></returns>
        public ReturnResult DelProductGongYi(string gyCode)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(gyCode))
                {
                    rsl.Message = "未能获取工艺编码";
                    return rsl;
                }
                StringBuilder sb = new StringBuilder();
                sb.Append("delete from fun_products_gx where gyCode='" + gyCode + "'");
                rsl = cmd.UpdateSql(sb.ToString());

            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 通用工序配置工艺序号方法
        /// </summary>
        /// <param name="gxCode"></param>
        /// <param name="orderNum"></param>
        /// <param name="list"></param>
        private void saveGXXH(string gxCode, string orderNum, ref List<Dictionary<string, string>> list)
        {
            var dic = new Dictionary<string, string>();
            bool isAdd = true;
            foreach (var d in list)
            {
                if (d["gxCode"] == gxCode)
                {
                    isAdd = false;
                    break;
                }
            }
            if (isAdd)
            {
                dic["gxCode"] = gxCode;
                dic["gxNum"] = orderNum;
                dic["number"] = "0";
                list.Add(dic);
            }

        }
        /// <summary>
        /// 根据工序大类获取子工序
        /// </summary>
        /// <param name="gxCode"></param>
        /// <returns></returns>
        public ReturnResult GetChildGongXu(string gxCode)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from fun_GxPrice_info where gxCode='" + gxCode + "'");
                sb.Append(" and isdel=0");
                var table = cmd.GetDataTable(sb.ToString());
                rsl.Result = true;
                rsl.Data = cmd.TableToDictionary(table);
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 根据品类编码获取生产工艺
        /// </summary>
        /// <param name="proType">品类编码</param>
        /// <param name="order">关联单号</param>
        /// <param name="rowNo">关联单行号</param>
        /// <returns></returns>
        public ReturnResult GetGongXuByProType(string proType, string gyCode, string order, string rowNo)
        {
            rsl = new ReturnResult();
            try
            {
                if (!string.IsNullOrWhiteSpace(order))
                {
                    string key = string.Format("{0}{1}{2}-PGY", order, rowNo, userLogin.UserInfo().userCode);
                    var data = Tools.Cache.GetCache(key);
                    if (data != null && !string.IsNullOrWhiteSpace(data.ToString()))
                    {
                        var json = JsonConvert.DeserializeObject<JObject>(data.ToString());
                        if (!string.IsNullOrWhiteSpace(json["gyData"].ToString()))
                        {
                            var arr = json["gyData"].ToString().Split(',');
                            StringBuilder sb = new StringBuilder();
                            sb.Append("select * from fun_GxPrice_info where isdel=0 and proType='" + proType + "'");
                            var cTable = cmd.GetDataTable(sb.ToString());

                            List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                            foreach (string s in arr)
                            {
                                if (!string.IsNullOrWhiteSpace(s))
                                {
                                    bool show = false;
                                    var cx_dr = cTable.Select("cgxCode='" + s.Trim() + "'");
                                    if (cx_dr.Length > 0)
                                    {
                                        show = true;
                                    }
                                    else
                                    {
                                        cx_dr = cTable.Select("gxCode='" + s.Trim() + "'");
                                        if (cx_dr.Length < 1)
                                        {
                                            show = true;
                                        }
                                    }
                                    if (show)
                                    {
                                        var d = new Dictionary<string, string>();
                                        d["gxCode"] = s.Trim();
                                        list.Add(d);

                                    }

                                }

                            }
                            rsl.Data = list;
                            rsl.Result = true;
                        }

                    }
                }

                if (!rsl.Result)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("select * from fun_products_gx where ");
                    sb.Append(" proCode='" + proType + "'");
                    if (!string.IsNullOrWhiteSpace(gyCode))
                    {
                        sb.Append("  and gyCode='" + gyCode + "'");
                    }
                    var table = cmd.GetDataTable(sb.ToString());
                    if (table.Rows.Count > 0)
                    {
                        rsl.Result = true;
                        rsl.Data = cmd.TableToDictionary(table);
                    }
                    else
                    {
                        rsl.Message = "没有数据";
                    }
                }


            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 删除存货工序
        /// </summary>
        /// <param name="proCode"></param>
        /// <returns></returns>
        public ReturnResult DelProductGx(string proCode)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("delete from fun_products_gx where ");
                sb.Append("proCode='" + proCode + "'");
                rsl = cmd.UpdateSql(sb.ToString());
                return rsl;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 获取存货配置工序
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageCount"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public ReturnResult ProductGxInfo(string pageIndex, string pageSize, ref string pageCount, string condition)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                var json = JsonConvert.DeserializeObject<JObject>(condition);
                if (json["plType"] != null && json["plType"].ToString() != "P-Pack")
                {
                    sb.Append("select typeCode from fun_Inventory_Info where proCode='" + json["proCode"].ToString() + "'");
                    var table = cmd.GetDataTable(sb.ToString());
                    string typeCode = table.Rows[0][0].ToString();
                    #region  获取存货品类
                    sb.Clear();
                    sb.Append("select * from fun_CommonData_Info where cType='SCTYPE' ");
                    sb.Append("and cMemo like'%" + typeCode + "%'");
                    table = cmd.GetDataTable(sb.ToString());
                    if (table.Rows.Count > 0)
                    {
                        if (table.Rows.Count > 1)
                        {
                            rsl.Message = "当前存货("+ json["proCode"].ToString() + ")属于多种品类，请检查设置";
                            return rsl;
                        }
                        else
                        {
                            json["proCode"] = table.Rows[0]["cCode"].ToString();
                        }
                    }
                    else
                    {
                        rsl.Message = "无法获取当前存货所属品类";
                        return rsl;
                    }
                    #endregion
                    sb.Clear();
                }
                
                if (json["plType"] != null && json["plType"].ToString() == "P-Pack")
                {
                    #region 包装计划
                    sb.Clear();
                    sb.Append(" isdel=0 and gxCode in ('BZ','QTBZ') ");
                    //if (!string.IsNullOrWhiteSpace(json["proCode"].ToString()))
                    //{
                    //    sb.Append(" and proType = '" + json["proCode"].ToString() + "'");
                    //}
                    if (!string.IsNullOrWhiteSpace(json["gyCode"].ToString()))
                    {
                        sb.Append(" and cgxCode like '%" + json["gyCode"].ToString() + "%'");
                    }
                    if (!string.IsNullOrWhiteSpace(json["gyName"].ToString()))
                    {
                        sb.Append(" and cgxName like '%" + json["gyName"].ToString() + "%'");
                    }

                    var list = cmd.PageList("fun_GxPrice_info", pageIndex, pageSize, sb.ToString(), "id desc", ref pageCount);

                    rsl.Data = list;
                    rsl.Result = true;
                    #endregion
                }
                else
                {
                    #region  生产工艺   其他计划 
                    sb.Clear();
                    sb.Append(" 1=1 ");
                    if (!string.IsNullOrWhiteSpace(json["proCode"].ToString()))
                    {
                        sb.Append(" and proCode = '" + json["proCode"].ToString() + "'");
                    }
                    if (!string.IsNullOrWhiteSpace(json["gyCode"].ToString()))
                    {
                        sb.Append(" and gyCode like '%" + json["gyCode"].ToString() + "%'");
                    }
                    if (!string.IsNullOrWhiteSpace(json["gyName"].ToString()))
                    {
                        sb.Append(" and gyName like '%" + json["gyName"].ToString() + "%'");
                    }
                    var list = cmd.PageList("V_ProductTypeGY_info", pageIndex, pageSize, sb.ToString(), "gyCode", ref pageCount);
                    rsl.Data = list;
                    rsl.Result = true;
                    #endregion
                }


            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 生产计划已选工序
        /// <param name="proCode">存货编码</param>
        /// </summary>
        public ReturnResult GetProductType(string proCode)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(proCode))
                {
                    rsl.Message = "货号信息获取失败";
                    return rsl;
                }
                var arr = proCode.Split(',');
             
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from fun_CommonData_Info where cMemo like '%'+ ");
                sb.Append("(select typeCode from fun_Inventory_Info where proCode='" + proCode + "')");
                sb.Append(" and cType='SCTYPE' ");

                var table = cmd.GetDataTable(sb.ToString());
                if (table.Rows.Count > 0)
                {
                    rsl.Result = true;
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d["tCode"] = table.Rows[0]["cCode"].ToString();
                    d["tName"] = table.Rows[0]["cName"].ToString();
                    rsl.Data = d;
                }
                else
                {
                    rsl.Message = "没有获取数据";
                }

            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;

        }
        /// <summary>
        /// 根据品类编码获取工序
        /// </summary>
        /// <param name="proCode"></param>
        /// <returns></returns>
        public ReturnResult getProductByCode(string proCode)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from V_ProductGongXu_info where ");
                sb.Append("proCode='" + proCode + "'");
                rsl.Data = cmd.TableToDictionary(cmd.GetDataTable(sb.ToString()));
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 更改生产工序状态
        /// </summary>
        /// <param name="dataId">数据id</param>
        /// <param name="status">当前状态编码</param>
        /// <returns></returns>
        public ReturnResult ChanageGxStatus(string dataId, string status)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();

                if (status == "Y")
                {
                    status = "N";
                }
                else
                {
                    status = "Y";
                }
                sb.Append("update fun_CommonData_Info set status='" + status + "' ");
                sb.Append("where id=" + dataId);
                rsl = cmd.UpdateSql(sb.ToString());
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 更新计算公式
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public ReturnResult UpdateExpression(string datas)
        {
            rsl = new ReturnResult();
            operList = new List<OperateModel>();
            try
            {
                var data = JsonConvert.DeserializeObject<DbCommonData>(datas);
                if (data.id != null && data.id > 0)
                {
                    oper.Data = data;
                    oper.Types = OperateModel.OperateType.Edit;
                    oper.Conditions = "id";
                    operList.Add(oper);
                }
                else
                {
                    #region 添加数据
                    data.createtime = getNow();
                    data.createuser = userLogin.UserInfo().userCode;
                    data.cType = "GXGS";
                    data.status = "Y";
                    data.isDel = 0;
                    data.cMemo = "工序计算公式";
                    oper = new OperateModel();
                    oper.Data = data;
                    oper.Types = OperateModel.OperateType.Add;
                    operList.Add(oper);
                    #endregion
                }
                if (operList.Count > 0)
                {
                    rsl = cmd.MoreUpdate(operList);
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 绩效公式列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageCount"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public ReturnResult getGongShiList(string pageIndex, string pageSize, ref string pageCount, string condition)
        {
            rsl = new ReturnResult();
            try
            {
                var json = JsonConvert.DeserializeObject<JObject>(condition);
                StringBuilder sb = new StringBuilder();
                sb.Append(" isdel=0 ");

                if (json.Property("parentCode") != null && !string.IsNullOrWhiteSpace(json["parentCode"].ToString()))
                {
                    sb.Append(" and parentCode='" + json["parentCode"].ToString() + "'");
                }
                if (!string.IsNullOrWhiteSpace(json["cCode"].ToString()))
                {
                    sb.Append(" and cCode like '%" + json["cCode"].ToString() + "%'");
                }
                var list = cmd.PageList("V_GongShi_info", pageIndex, pageSize, sb.ToString(), "id desc", ref pageCount);
                rsl.Data = list;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 获取工序生产机台信息
        /// </summary>
        /// <param name="gxCode"></param>
        /// <returns></returns>
        public ReturnResult GetGxMachine(string gxCode)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from fun_CommonData_Info where isdel=0 ");
                sb.Append(" and specFile='" + gxCode + "' and cType='PM'");
                var table = cmd.GetDataTable(sb.ToString());
                rsl.Result = true;
                rsl.Data = cmd.TableToDictionary(table);

            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        
        /// <summary>
        /// 获取织造、整经  生产机台信息
        /// </summary>
        /// <returns></returns>
        public ReturnResult GetZBMachine(string mType)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from fun_machine_info where isdel=0 ");
                if (!string.IsNullOrWhiteSpace(mType))
                {
                    //if (mType.Contains(','))
                    //{
                    //    sb.Append(" and mType in (" + mType + ") ");
                    //}
                    //else
                    //{
                        sb.Append(" and mType='" + mType + "' ");
                    //}
                }
                sb.Append("order by id desc");
                var table = cmd.GetDataTable(sb.ToString());
                rsl.Result = true;
                rsl.Data = cmd.TableToDictionary(table);

            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 有效生产工序
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public ReturnResult GetGongXuList(string conditions)
        {
            rsl = new ReturnResult();
            try
            {
                var json = JsonConvert.DeserializeObject<JObject>(conditions);
                StringBuilder sb = new StringBuilder();
                sb.Append("select c.cCode,c.cName,c.orderNum,c.id,c.status,c.cMemo,c.cValues,d.name statusName ");
                sb.Append("from fun_CommonData_Info c inner join sys_dictionaries_info d ");
                sb.Append("on c.cValues=d.code and d.types='ct'");
                sb.Append(" where isdel=0 and  cType='Gx'");
                sb.Append(" and cCode is not null and cCode !='' ");
                sb.Append(" order by convert(int,orderNum)  ");
                var gxTable = cmd.GetDataTable(sb.ToString());

                gxTable.Columns.Add("hasChild");
                #region   判断工序大类是否有子工序，用于在前台 删除和修改时判断，有子工序不允许删除，只可以改顺序和备注
                foreach (DataRow dr in gxTable.Rows)
                {
                    sb.Clear();
                    sb.Append("seleCt count(*) count from fun_CommonData_Info comm inner join fun_GxPrice_info gx ");
                    sb.Append(" on gx.gxCode = comm.cCode where comm.cCode='" + dr["cCode"].ToString() + "' ");
                    var cgxTable = cmd.GetDataTable(sb.ToString());
                    if (Convert.ToInt32(cgxTable.Rows[0][0]) > 0)
                        dr["hasChild"] = "1";
                    else
                        dr["hasChild"] = "0";
                }
                #endregion
                rsl.Data = cmd.TableToDictionary(gxTable);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 获取子工序数据信息
        /// </summary>
        /// <param name="gxCode"></param>
        /// <returns></returns>
        public ReturnResult GetChildGongXuList(string gxCode)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select cCode,cName,id,cMemo,cValues from fun_CommonData_Info");
                sb.Append(" where isdel=0 and  cType='GxCM' and specFile='" + gxCode + "'");
                sb.Append(" ");
                var gxTable = cmd.GetDataTable(sb.ToString());
                rsl.Data = cmd.TableToDictionary(gxTable);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 获取品类对应工序下拉数据信息
        /// </summary>
        /// <returns></returns>
        public ReturnResult selectGxData(string typeCode)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select distinct gyCode value,gyName name  from fun_products_gx  ");
                if (!string.IsNullOrWhiteSpace(typeCode))
                    sb.Append(" where proCode in (select cCode from fun_CommonData_Info where cType = 'SCTYPE' and cMemo = '" + typeCode + "')");
                rsl.Data = cmd.TableToDictionary(cmd.GetDataTable(sb.ToString()));
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }


        /// <summary>
        /// 人员班组
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public ReturnResult UserGroupInfo(string pageIndex, string pageSize, ref string pageCount, string condition)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("  status='Y' and isAdmin=0");//isdel=0 and
                if (!string.IsNullOrWhiteSpace(condition))
                {
                    var json = JsonConvert.DeserializeObject<JObject>(condition);
                    foreach (JProperty obj in json.Properties())
                    {
                        if (!string.IsNullOrWhiteSpace(obj.Value.ToString()))
                        {
                            if (!string.IsNullOrWhiteSpace(sb.ToString()))
                            {
                                sb.Append(" and ");
                            }
                            if (obj.Name == "groupCode" || obj.Name == "parentCode")
                            {
                                sb.Append(obj.Name + "='" + obj.Value.ToString() + "' ");
                            }
                            else if (obj.Name == "groupCodes")
                            {
                                var arr = obj.Value.ToString().Split(',');
                                string gcodes = "";
                                foreach (string s in arr)
                                {
                                    if (!string.IsNullOrWhiteSpace(s))
                                    {
                                        gcodes +=  s + ",";
                                    }
                                }
                                sb.Append("groupCode in(" + gcodes.TrimEnd(',') + ")");
                            }
                            else
                            {
                                sb.Append(obj.Name + " like '%" + obj.Value.ToString() + "%' ");
                            }
                        }
                    }
                }
                var list = cmd.PageList("V_productionSet_userGroup", pageIndex, pageSize, sb.ToString(), "userCode desc", ref pageCount);
                rsl.Data = list;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 添加班组成员
        /// </summary>
        /// <param name="users"></param>
        /// <param name="groupCode"></param>
        /// <returns></returns>
        public ReturnResult AddGroupUser(string users, string groupCode)
        {
            rsl = new ReturnResult();
            operList = new List<OperateModel>();
            try
            {
                if (string.IsNullOrWhiteSpace(users))
                {
                    rsl.Message = "没有人员信息";
                    return rsl;
                }
                if (string.IsNullOrWhiteSpace(groupCode))
                {
                    rsl.Message = "班组信息不允许为空";
                    return rsl;
                }
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from fun_Users_gangwei where isdel=0 and dType='UGP' ");
                var table = cmd.GetDataTable(sb.ToString());
                var uArr = users.Split(',');
                foreach (string u in uArr)
                {
                    if (!string.IsNullOrWhiteSpace(u))
                    {
                        #region 员工支持分配多个班组
                        var dr = table.Select("userCode='" + u + "' and groupCode='" + groupCode + "'");
                        if (dr.Length > 0)
                        {
                            rsl.Message = string.Format("该账号已分配在此班组:{0},{1}", u, groupCode);
                            return rsl;
                        }
                        else
                        {
                            #region 添加信息
                            DbUserPosition up = new DbUserPosition();
                            up.userCode = u;
                            up.groupCode = groupCode;
                            up.createtime = getNow();
                            up.isdel = 0;
                            up.dType = "UGP";
                            up.createuser = userLogin.UserInfo().userCode;
                            oper = new OperateModel();
                            oper.Data = up;
                            oper.Types = OperateModel.OperateType.Add;
                            operList.Add(oper);
                            #endregion
                        }
                        #endregion
                    }
                }
                if (operList.Count > 0)
                {
                    rsl = cmd.MoreUpdate(operList);
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 删除班组人员
        /// </summary>
        /// <param name="users"></param>
        /// <returns></returns>
        //public ReturnResult DelGroupUser(string users)
        //{
        //    rsl = new ReturnResult();
        //    operList = new List<OperateModel>();
        //    try
        //    {
        //        if (string.IsNullOrWhiteSpace(users))
        //        {
        //            rsl.Message = "没有人员信息";
        //            return rsl;
        //        }
        //        StringBuilder sb = new StringBuilder();
        //        sb.Append("select * from fun_Users_gangwei where isdel=0 and dType='UGP'");
        //        var table = cmd.GetDataTable(sb.ToString());
        //        var uArr = users.Split(',');
        //        foreach (string u in uArr)
        //        {
        //            if (!string.IsNullOrWhiteSpace(u))
        //            {
        //                var dr = table.Select("userCode='" + u + "'");
        //                if (dr.Length < 1)
        //                {
        //                    rsl.Message = string.Format("该账号无需删除班组信息:{0}", u);
        //                    return rsl;
        //                }
        //                else
        //                {
        //                    #region 删除信息
        //                    DbUserPosition up = new DbUserPosition();
        //                    up.userCode = u;
        //                    up.isdel = 1;
        //                    up.delDate = getNow();
        //                    up.deluser = userLogin.UserInfo().userCode;
        //                    oper = new OperateModel();
        //                    oper.Data = up;
        //                    oper.Types = OperateModel.OperateType.Edit;
        //                    oper.Conditions = "userCode";
        //                    operList.Add(oper);
        //                    #endregion
        //                }
        //            }
        //        }
        //        if (operList.Count > 0)
        //        {
        //            rsl = cmd.MoreUpdate(operList);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        rsl.Message = ex.Message;
        //    }
        //    return rsl;
        //} 

        public ReturnResult DelGroupUser(string ids)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(ids))
                {
                    rsl.Message = "没有人员信息";
                    return rsl;
                }
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from fun_Users_gangwei where isdel=0 and dType='UGP'");
                sb.Append(" and id in (" + ids + ") ");
                var table = cmd.GetDataTable(sb.ToString());
                if (table.Rows.Count < 1)
                {
                    rsl.Message = string.Format("无需要删除的信息");
                    return rsl;
                }
                sb.Clear();
                sb.Append("update fun_Users_gangwei set isdel = '1',delDate='" + getNow() + "',");
                sb.Append("deluser='" + userLogin.UserInfo().userCode + "' where id in (" + ids + ") ");
                rsl = cmd.UpdateSql(sb.ToString());

            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 获取子工序信息
        /// </summary>
        /// <param name="gxCode">工序编码</param>
        /// <returns></returns>
        public ReturnResult GongXuChildren(string gxCode)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select cCode,cName from fun_CommonData_Info where isdel=0 and status='Y'");
                sb.Append(" and specFile='" + gxCode + "' and cType='GxCM'");
                var table = cmd.GetDataTable(sb.ToString());
                if (table.Rows.Count < 1)
                {
                    DataRow r = table.NewRow();
                    r["cCode"] = "N";
                    r["cName"] = "无";
                    table.Rows.Add(r);
                }
                rsl.Result = true;
                rsl.Data = cmd.TableToDictionary(table);
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        #region 品类生产工艺树
        /// <summary>
        /// 品类生产工艺树
        /// </summary>
        /// <param name="proType">品类</param>
        /// <returns></returns>
        public ReturnResult GongXuNavigation(string proType, string plCode)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from fun_CommonData_Info where cType='GX' ");
                sb.Append(" and isDel=0 and status='Y' order by orderNum asc");
                var table = cmd.GetDataTable(sb.ToString());//获取全部有效菜单信息
                var cTable = new DataTable();
                sb.Clear();
                sb.Append("select * from fun_GxPrice_info where isdel=0 and proType='" + proType + "'");
                cTable = cmd.GetDataTable(sb.ToString());
                List<Dictionary<string, object>> menuList = new List<Dictionary<string, object>>();
                #region 构建数据
                var fMenu = table.Select("cType='Gx'");//获取所有父级菜单
                for (int i = 0; i < fMenu.Length; i++)
                {
                    var fdic = new Dictionary<string, object>();
                    fdic["title"] = string.Format("{0}({1})", fMenu[i]["cName"].ToString(), fMenu[i]["cCode"].ToString());
                    fdic["id"] = fMenu[i]["cCode"].ToString().Trim();
                    fdic["spread"] = "true";

                    #region 子菜单
                    List<Dictionary<string, object>> cList = new List<Dictionary<string, object>>();
                    this.ChildUrl(cTable, fMenu[i]["cCode"].ToString(), ref cList);
                    fdic["children"] = cList;
                    #endregion
                    menuList.Add(fdic);
                }
                #endregion
                rsl.Data = menuList;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        #endregion

        #region 班组成员树
        /// <summary>
        /// 班组成员树
        /// </summary>
        /// <returns></returns>
        public ReturnResult GroupUserTree(string groupCode)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from fun_CommonData_Info where (cType in('GXG') ");
                sb.Append(" and isDel=0 and status='Y')");
                sb.Append(" or cCode in(select parentCode from  fun_CommonData_Info where isDel=0 and status='Y' ");
                if (!string.IsNullOrWhiteSpace(groupCode))
                {
                    sb.Append(" and cCode='" + groupCode + "' ) ");
                }
                else
                {
                    sb.Append(" )  and cCode='ZB' ");
                }
                //sb.Append("  ");
                var table = cmd.GetDataTable(sb.ToString());//获取全部有效信息（工序，班组）
                sb.Clear();
                sb.Append("select ug.groupCode,u.userCode,u.userName from fun_Users_gangwei ug");
                sb.Append(" inner join sys_users_info u on u.userCode=ug.userCode ");
                sb.Append(" where ug.isdel=0");
                var uTable = cmd.GetDataTable(sb.ToString());//获取全部人员

                List<Dictionary<string, object>> menuList = new List<Dictionary<string, object>>();
                #region 构建数据
                var fMenu = table.Select("cType='Gx'");//获取工序
                for (int i = 0; i < fMenu.Length; i++)
                {
                    var fdic = new Dictionary<string, object>();
                    fdic["title"] = string.Format("{0}({1})", fMenu[i]["cName"].ToString(), fMenu[i]["cCode"].ToString());
                    fdic["id"] = fMenu[i]["cCode"].ToString().Trim();
                    fdic["spread"] = "true";

                    #region 子菜单
                    List<Dictionary<string, object>> cList = new List<Dictionary<string, object>>();
                    this.UserChildUrl(table, uTable, fMenu[i]["cCode"].ToString(), ref cList);
                    fdic["children"] = cList;
                    #endregion
                    menuList.Add(fdic);
                }
                #endregion
                rsl.Data = menuList;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 子菜单生成方法(递归)
        /// </summary>
        /// <param name="table">生产子工序</param>
        /// <param name="cCode"></param>
        /// <param name="menuName"></param>
        /// <param name="icon"></param>
        /// <param name="chlist"></param>
        private void ChildUrl(DataTable table, string cCode, ref List<Dictionary<string, object>> chlist)
        {
            var dr = table.Select("gxCode='" + cCode + "'");
            if (dr.Length > 0)
            {
                for (int x = 0; x < dr.Length; x++)
                {
                    List<Dictionary<string, object>> tempList = new List<Dictionary<string, object>>();
                    var cdic = new Dictionary<string, object>();
                    cdic["title"] = string.Format("{0}({1})", dr[x]["cgxName"].ToString(), dr[x]["cgxCode"].ToString());
                    cdic["id"] = dr[x]["cgxCode"].ToString().Trim();
                    ChildUrl(table, dr[x]["cgxCode"].ToString(), ref tempList);
                    cdic["children"] = tempList;
                    chlist.Add(cdic);
                }
            }
        }
        #endregion

        private void UserChildUrl(DataTable gTable, DataTable uTable, string cCode, ref List<Dictionary<string, object>> chlist)
        {
            var dr = gTable.Select("parentCode='" + cCode + "' and cType='GXG'");
            if (dr.Length > 0)
            {
                for (int x = 0; x < dr.Length; x++)
                {
                    List<Dictionary<string, object>> tempList = new List<Dictionary<string, object>>();
                    var cdic = new Dictionary<string, object>();
                    cdic["title"] = string.Format("{0}({1})", dr[x]["cName"].ToString(), dr[x]["cCode"].ToString());
                    cdic["id"] = dr[x]["cCode"].ToString().Trim();
                    cdic["spread"] = "true";
                    UserChildUrl(gTable, uTable, dr[x]["cCode"].ToString(), ref tempList);
                    cdic["children"] = tempList;
                    chlist.Add(cdic);
                }
            }
            else
            {
                dr = uTable.Select("groupCode='" + cCode + "'");
                List<Dictionary<string, object>> tempList = new List<Dictionary<string, object>>();
                foreach (DataRow r in dr)
                {
                    var cdic = new Dictionary<string, object>();
                    cdic["title"] = string.Format("{0}({1})", r["userName"].ToString(), r["userCode"].ToString());
                    cdic["id"] = "U-" + r["userCode"].ToString().Trim();
                    chlist.Add(cdic);
                }
            }
        }
        /// <summary>
        /// 工序工价
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageCount"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public ReturnResult ChildGongXuPriceInfo(string pageIndex, string pageSize, ref string pageCount, string condition)
        {
            rsl = new ReturnResult();
            try
            {
                var json = JsonConvert.DeserializeObject<JObject>(condition);
                StringBuilder sb = new StringBuilder();
                sb.Append("isdel=0 ");
                sb = CreateSelectCondition(sb, condition);
                var list = cmd.PageList("V_GongXuPrice_info", pageIndex, pageSize, sb.ToString(), "proType,gxCode,cgxCode", ref pageCount);
                var dic = new Dictionary<string, string>();
                dic["isdel"] = "0";
                dic["id"] = "0";
                dic["gxName"] = "";
                dic["proTypeName"] = "";
                list.Add(dic);

                rsl.Data = list;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 获取工序下拉数据信息
        /// </summary>
        /// <returns></returns>
        public ReturnResult GxDataSelect(string typeCode)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select cCode value,cName name from fun_CommonData_Info ");
                sb.Append(" where isdel=0 and cType='" + typeCode + "' and cCode is not null");
                sb.Append(" order by convert(int,orderNum) ");
                rsl.Data = cmd.TableToDictionary(cmd.GetDataTable(sb.ToString()));
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 工序单价保存方法
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public ReturnResult UpdateGxPrice(string datas)
        {
            rsl = new ReturnResult();
            operList = new List<OperateModel>();
            try
            {
                var json = JsonConvert.DeserializeObject<JObject>(datas);
                DbGongXuPrice gxPrice = new DbGongXuPrice();
                #region 防空值
                if (json.Property("cgxCode") == null || string.IsNullOrWhiteSpace(json["cgxCode"].ToString()))
                {
                    rsl.Message = "工序编码不允许为空";
                    return rsl;
                }

                if (json.Property("cgxName") == null || string.IsNullOrWhiteSpace(json["cgxName"].ToString()))
                {
                    rsl.Message = "工序名称不允许为空";
                    return rsl;
                }

                if (json.Property("gxName") == null || string.IsNullOrWhiteSpace(json["gxName"].ToString()))
                {
                    rsl.Message = "请先选择工序大类";
                    return rsl;
                }

                if (json.Property("proTypeName") == null || string.IsNullOrWhiteSpace(json["proTypeName"].ToString()))
                {
                    rsl.Message = "请先选择品类";
                    return rsl;
                }
                #endregion
                gxPrice.proType = json["proType"].ToString();
                gxPrice.gxCode = json["gxCode"].ToString();
                gxPrice.cgxCode = json["cgxCode"].ToString();
                gxPrice.cgxName = json["cgxName"].ToString();
                gxPrice.isDel = 0;
                #region 价格不填的话默认为0
                if (!string.IsNullOrWhiteSpace(json["yPrice"].ToString()))
                {
                    gxPrice.yPrice = json["yPrice"].ToString();
                }
                else
                {
                    gxPrice.yPrice = "0";
                }
                if (datas.Contains("nPrice") && !string.IsNullOrWhiteSpace(json["nPrice"].ToString()))
                {
                    gxPrice.nPrice = json["nPrice"].ToString();
                }
                else
                {
                    gxPrice.nPrice = "0";
                }
                #endregion
                oper = new OperateModel();
                string sql = "select top 1 * from fun_GxPrice_info where cgxCode='" + json["cgxCode"].ToString() + "' and isDel=0 ";
                var qTable = cmd.GetDataTable(sql);
                if (json["id"].ToString() == "0" || string.IsNullOrWhiteSpace(json["id"].ToString()))
                {
                    #region 添加
                    if (qTable.Rows.Count > 0)
                    {
                        rsl.Message = "工序编码已存在：" + json["cgxCode"].ToString();
                        return rsl;
                    }
                    gxPrice.createtime = getNow();
                    gxPrice.createuser = userLogin.UserInfo().userCode;
                    oper.Types = OperateModel.OperateType.Add;
                    #endregion
                }
                else
                {
                    #region 修改
                    if (qTable.Rows.Count > 0 && qTable.Rows[0]["id"].ToString() != json["id"].ToString())
                    {
                        rsl.Message = "工序编码已存在：" + json["cgxCode"].ToString();
                        return rsl;
                    }
                    gxPrice.id = int.Parse(json["id"].ToString());
                    oper.Conditions = "id";
                    oper.Types = OperateModel.OperateType.Edit;
                    #endregion
                }
                oper.Data = gxPrice;
                operList.Add(oper);

                #region 关联绩效
                sql = "select * from pw_employeeWage_info where uPrice='0/0' and isdel=0" +
                   " and gxCode='" + gxPrice.cgxCode + "'";
                var wtable = cmd.GetDataTable(sql);
                DbemployeeWage wage;
                foreach (DataRow r in wtable.Rows)
                {
                    wage = new DbemployeeWage();
                    wage.id = int.Parse(r["id"].ToString());
                    wage.uPrice = String.Format("{0}/{1}", gxPrice.yPrice, gxPrice.nPrice);
                    wage.total = (double.Parse(gxPrice.yPrice) * double.Parse(r["yNum"].ToString()) + double.Parse(gxPrice.nPrice) * double.Parse(r["nNum"].ToString())).ToString();
                    oper = new OperateModel();
                    oper.Data = wage;
                    oper.Conditions = "id";
                    oper.Types = OperateModel.OperateType.Edit;
                    operList.Add(oper);

                }
                #endregion
                rsl = cmd.MoreUpdate(operList);
                #region   工序单价修改成功(合格价和不合格不为0/空)后， 查找此工序的报工记录，有没有合格单价和不合格单价为0的，有 则修改其绩效。
                if (rsl.Result)
                {
                    if (json["yPrice"] != null && !string.IsNullOrWhiteSpace(json["yPrice"].ToString()) && json["yPrice"].ToString() != "0" &&
                        json["nPrice"] != null && !string.IsNullOrWhiteSpace(json["nPrice"].ToString()) && json["nPrice"].ToString() != "0")
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append("select * from pw_employeeWage_info where  isdel=0 and ");
                        sb.Append(" gxCode='" + json["cgxCode"].ToString() + "' and uPrice ='0/0'  ");
                        var wageTable = cmd.GetDataTable(sb.ToString());
                        if (wageTable.Rows.Count > 0)
                        {
                            List<string> sqlList = new List<string>();
                            foreach (DataRow dr in wageTable.Rows)
                            {
                                sb.Clear();
                                var price = string.Format("{0}/{1}", json["yPrice"].ToString(), json["nPrice"].ToString());
                                var amount = (double.Parse(json["yPrice"].ToString()) * double.Parse(dr["yNum"].ToString()) +
                                    double.Parse(json["nPrice"].ToString()) * double.Parse(dr["nNum"].ToString())).ToString();
                                sb.Append("update pw_employeeWage_info set uPrice='" + price);
                                sb.Append("',total='" + amount + "' where id=" + dr["id"]);

                                sqlList.Add(sb.ToString());
                            }
                            rsl = cmd.MoreUpdate(sqlList);
                        }
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 删除工序单价
        /// </summary>
        /// <param name="dataId"></param>
        /// <returns></returns>
        public ReturnResult DelGxPrice(string dataId)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("seleCt count(*) count from fun_GxPrice_info gx inner join ");
                sb.Append(" pi_ProductionPlan_process pces on pces.gxCode = gx.cgxCode where gx.id=" + dataId);
                var gxTable = cmd.GetDataTable(sb.ToString());
                if (Convert.ToInt32(gxTable.Rows[0][0]) > 0)
                {
                    rsl.Message = "此工序已在生产过程中应用，暂不支持删除。";
                    return rsl;
                }
                else
                {
                    DbGongXuPrice p = new DbGongXuPrice();
                    p.isDel = 1;
                    p.delDate = getNow();
                    p.delUser = userLogin.UserInfo().userCode;
                    p.id = int.Parse(dataId);
                    oper = new OperateModel();
                    oper.Data = p;
                    oper.Conditions = "id";
                    oper.Types = OperateModel.OperateType.Edit;
                    rsl = cmd.Edit(oper);
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 工序生产小组
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageCount"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public ReturnResult GongXuGroup(string pageIndex, string pageSize, ref string pageCount, string condition)
        {
            rsl = new ReturnResult();
            try
            {
                //var json = JsonConvert.DeserializeObject<JObject>(condition);
                StringBuilder sb = new StringBuilder();
                sb.Append("isdel=0 ");
                //sb = CreateSelectCondition(sb, condition);
                #region 检索条件
                if (!string.IsNullOrWhiteSpace(condition))
                {
                    var json = JsonConvert.DeserializeObject<JObject>(condition);
                    foreach (JProperty obj in json.Properties())
                    {
                        if (!string.IsNullOrWhiteSpace(obj.Value.ToString()))
                        {
                            if (obj.Name.ToString().Equals("userCode") || obj.Name.ToString().Equals("userName"))
                            {
                                continue;
                            }
                            if (!string.IsNullOrWhiteSpace(sb.ToString()))
                            {
                                sb.Append(" and ");
                            }
                            sb.Append(obj.Name + " like '%" + obj.Value.ToString() + "%' ");
                        }
                    }
                }
                #endregion
                var list = cmd.PageList("V_GongXuGroup_info", pageIndex, pageSize, sb.ToString(), "id desc", ref pageCount);
                var dic = new Dictionary<string, string>();
                dic["isdel"] = "0";
                dic["id"] = "0";
                dic["gxName"] = "";
                dic["leader"] = "";
                dic["userName"] = "";
                list.Add(dic);

                rsl.Data = list;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 获取工序生产小组
        /// </summary>
        /// <param name="gxCode">工序编码</param>
        /// <returns></returns>
        public ReturnResult GetGongXuGroup(string gxCode)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from V_GongXuGroup_info where");
                sb.Append(" isdel=0  and status='Y' ");
                if (!string.IsNullOrWhiteSpace(gxCode))
                {
                    if (gxCode.Contains("BZ"))
                        sb.Append("and parentCode like '%BZ' ");
                    else
                        sb.Append("and parentCode='" + gxCode + "' ");
                }
                
                sb.Append(" order by cCode ");
                var table = cmd.GetDataTable(sb.ToString());
                if (table.Rows.Count > 0)
                {
                    rsl.Data = cmd.TableToDictionary(table);
                    rsl.Result = true;
                }
                else
                {
                    List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                    rsl.Result = true;
                    rsl.Data = list;
                    rsl.Message = "没有数据";
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 保存生产小组
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public ReturnResult UpdateGxGroup(string datas)
        {
            rsl = new ReturnResult();
            operList = new List<OperateModel>();
            try
            {
                var json = JsonConvert.DeserializeObject<JObject>(datas);
                DbCommonData group = new DbCommonData();
                #region 防空值
                if (json.Property("cCode") == null || string.IsNullOrWhiteSpace(json["cCode"].ToString()))
                {
                    rsl.Message = "小组编码不允许为空";
                    return rsl;
                }

                if (json.Property("cName") == null || string.IsNullOrWhiteSpace(json["cName"].ToString()))
                {
                    rsl.Message = "小组名称不允许为空";
                    return rsl;
                }

                if (json.Property("gxName") == null || string.IsNullOrWhiteSpace(json["gxName"].ToString()))
                {
                    rsl.Message = "请先选择工序大类";
                    return rsl;
                }

                #endregion
                if (json["id"].ToString().Equals("0") && json["gxCode"] != null)
                {
                    group.parentCode = json["gxCode"].ToString();
                }
                else
                {
                    group.parentCode = json["parentCode"].ToString();
                }
                group.cCode = json["cCode"].ToString();
                group.cName = json["cName"].ToString();
                group.isDel = 0;
                group.status = "Y";
                group.cType = "GXG";
                group.leader = json["leader"].ToString();
                oper = new OperateModel();
                string sql = "select top 1 * from fun_CommonData_Info where cCode='" + json["cCode"].ToString() + "' " +
                    "and isDel=0";
                var qTable = cmd.GetDataTable(sql);
                if (json["id"].ToString() == "0" || string.IsNullOrWhiteSpace(json["id"].ToString()))
                {
                    if (qTable.Rows.Count > 0)
                    {
                        rsl.Message = "编码已存在：" + json["cCode"].ToString();
                        return rsl;
                    }
                    group.createtime = getNow();
                    group.createuser = userLogin.UserInfo().userCode;
                    oper.Types = OperateModel.OperateType.Add;
                }
                else
                {
                    if (qTable.Rows.Count > 0 && qTable.Rows[0]["id"].ToString() != json["id"].ToString())
                    {
                        rsl.Message = "编码已存在：" + json["cCode"].ToString();
                        return rsl;
                    }
                    group.id = int.Parse(json["id"].ToString());
                    oper.Conditions = "id";
                    oper.Types = OperateModel.OperateType.Edit;
                }
                oper.Data = group;
                operList.Add(oper);
                rsl = cmd.MoreUpdate(operList);
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 删除班组
        /// </summary>
        /// <param name="dataId"></param>
        /// <returns></returns>
        public ReturnResult DelGxGroup(string dataId)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                #region 当前班组是否已分配员工
                sb.Append("select g.groupCode from fun_CommonData_Info c ");
                sb.Append("inner join fun_Users_gangwei g on g.groupCode = c.cCode and c.cType = 'gxg' ");
                sb.Append("where c.isDel = 0 and g.isdel = 0 and c.id ="+ dataId);
                var ryTable = cmd.GetDataTable(sb.ToString());
                if (ryTable.Rows.Count > 0)
                {
                    rsl.Message = "当前班组已分配员工，暂不支持删除";
                    return rsl;
                }
                #endregion

                DbCommonData p = new DbCommonData();
                p.isDel = 1;
                p.delDate = getNow();
                p.delUser = userLogin.UserInfo().userCode;
                p.id = int.Parse(dataId);
                oper = new OperateModel();
                oper.Data = p;
                oper.Conditions = "id";
                oper.Types = OperateModel.OperateType.Edit;
                rsl = cmd.Edit(oper);
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 保存销售任务
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public ReturnResult UpdateUSTarget(string datas)
        {
            rsl = new ReturnResult();
            operList = new List<OperateModel>();
            try
            {
                var json = JsonConvert.DeserializeObject<JObject>(datas);
                DbSalesTarget target = new DbSalesTarget();
                #region 防空值
                if (json.Property("userCode") == null || string.IsNullOrWhiteSpace(json["userCode"].ToString()))
                {
                    rsl.Message = "人员信息不允许为空";
                    return rsl;
                }

                if (json.Property("hYear") == null || string.IsNullOrWhiteSpace(json["hYear"].ToString()))
                {
                    rsl.Message = "任务年份不允许为空";
                    return rsl;
                }

                if (json.Property("value") == null || string.IsNullOrWhiteSpace(json["value"].ToString()))
                {
                    rsl.Message = "任务数量不允许为空";
                    return rsl;
                }

                #endregion
                target.userCode = json["userCode"].ToString();
                target.hYear = json["hYear"].ToString();
                target.hMonth = json["hMonth"].ToString();
                target.value = json["value"].ToString();
                target.isDel = 0;

                oper = new OperateModel();
                string sql = "select top 1 * from fun_SaleorTarget_info where userCode='" + json["userCode"].ToString() + "' " +
                    " and hYear='" + json["hYear"].ToString() + "' and hMonth='" + json["hMonth"].ToString() + "' and isDel=0 ";
                var qTable = cmd.GetDataTable(sql);
                if (json["id"].ToString() == "0" || string.IsNullOrWhiteSpace(json["id"].ToString()))
                {
                    if (qTable.Rows.Count > 0)
                    {
                        rsl.Message = "当前人员重复分配任务：" + json["userCode"].ToString()+"-"+ json["hYear"].ToString() + "-" + json["hMonth"].ToString();
                        return rsl;
                    }
                    target.createtime = getNow();
                    target.createuser = userLogin.UserInfo().userCode;
                    oper.Types = OperateModel.OperateType.Add;
                }
                else
                {
                    if (qTable.Rows.Count > 0 && qTable.Rows[0]["id"].ToString() != json["id"].ToString())
                    {
                        rsl.Message = "当前人员重复分配任务：" + json["userCode"].ToString() + "-" + json["hYear"].ToString() + "-" + json["hMonth"].ToString();
                        return rsl;
                    }
                    target.id = int.Parse(json["id"].ToString());
                    oper.Conditions = "id";
                    oper.Types = OperateModel.OperateType.Edit;
                }
                oper.Data = target;
                operList.Add(oper);
                rsl = cmd.MoreUpdate(operList);
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 删除销售任务
        /// </summary>
        /// <param name="dataId"></param>
        /// <returns></returns>
        public ReturnResult DelUSTarget(string dataId)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();

                DbSalesTarget target = new DbSalesTarget();
                target.isDel = 1;
                target.delMsg = getNow()+";"+ userLogin.UserInfo().userCode;
                target.id = int.Parse(dataId);
                oper = new OperateModel();
                oper.Data = target;
                oper.Conditions = "id";
                oper.Types = OperateModel.OperateType.Edit;
                rsl = cmd.Edit(oper);
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 更改生产工艺名称
        /// </summary>
        /// <param name="value"></param>
        /// <param name="gyCode"></param>
        /// <returns></returns>
        public ReturnResult EditGongYiGongXuName(string value, string gyCode)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                if (string.IsNullOrWhiteSpace(value))
                {
                    rsl.Message = "工艺名称不允许为空";
                    return rsl;
                }
                sb.Append("update fun_products_gx set gyName='" + value + "'");
                sb.Append(" where gyCode='" + gyCode + "'");
                rsl = cmd.UpdateSql(sb.ToString());
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }/// <summary>
        /// 更改生产工艺编码
        /// </summary>
        /// <param name="value"></param>
        /// <param name="gyCode"></param>
        /// <returns></returns>
        public ReturnResult EditGongYiGongXuCode(string value, string gyCode)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                if (string.IsNullOrWhiteSpace(value))
                {
                    rsl.Message = "工艺编码不允许为空";
                    return rsl;
                }
                sb.Append("select * from fun_products_gx where gyCode='"+ value + "'");
                var table = cmd.GetDataTable(sb.ToString());
                if (table.Rows.Count > 0)
                {
                    rsl.Message="编码"+ value + "已存在";
                    return rsl;
                }
                sb.Clear();
                sb.Append("update fun_products_gx set gyCode='" + value + "'");
                sb.Append(" where gyCode='" + gyCode + "'");
                rsl = cmd.UpdateSql(sb.ToString());
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 获取全部班组人员
        /// </summary>
        /// <returns></returns>
        public ReturnResult GetGroupUserInfo()
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from V_Users_Group where isdel=0");
                var table = cmd.GetDataTable(sb.ToString());
                rsl.Data = cmd.TableToDictionary(table);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;

        }
        /// <summary>
        /// 获取水洗标号信息列表
        /// </summary>
        /// <param name="value"></param>
        /// <param name="dataId"></param>
        /// <returns></returns>
        public ReturnResult ShuiXiBiaoInfo(string pageIndex, string pageSize, ref string pageCount, string condition)
        {
            rsl = new ReturnResult();
            try
            {
                var json = JsonConvert.DeserializeObject<JObject>(condition);
                StringBuilder sb = new StringBuilder();
                sb.Append("isdel=0 ");
                sb = CreateSelectCondition(sb, condition);
                var list = cmd.PageList("fun_ShuiXiBiao_Info", pageIndex, pageSize, sb.ToString(), "id desc", ref pageCount);
                var dic = new Dictionary<string, string>();

                dic["isdel"] = "0";
                dic["id"] = "0";
                dic["proCode"] = "";
                dic["proName"] = "";
                dic["proColor"] = "";
                dic["brand"] = "";
                //dic["cusCode"] = "";
                //dic["cusName"] = "";

                list.Add(dic);

                rsl.Data = list;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 获取存货
        /// </summary>
        /// <returns></returns>
        public ReturnResult getproName(string name)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select proCode,proName from fun_Inventory_Info where");
                sb.Append(" isdel=0  and status='Y' ");
                if (!string.IsNullOrWhiteSpace(name))
                {
                    sb.Append("and proCode like '%" + name + "%' or proName like '%" + name + "%'");
                }
                var table = cmd.GetDataTable(sb.ToString());
                if (table.Rows.Count > 0)
                {
                    rsl.Data = cmd.TableToDictionary(table);
                    rsl.Result = true;
                }
                else
                {
                    List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                    rsl.Result = true;
                    rsl.Data = list;
                    rsl.Message = "没有数据";
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 保存水洗标
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public ReturnResult UpdateShuiXiBiao(string datas)
        {
            rsl = new ReturnResult();
            operList = new List<OperateModel>();
            try
            {
                string ys = "-", sb = "-";
                var json = JsonConvert.DeserializeObject<JObject>(datas);
                DbShuiXiBiao sxb = new DbShuiXiBiao();
                #region 防空值
                if (json.Property("outBarcode") == null || string.IsNullOrWhiteSpace(json["outBarcode"].ToString()))
                {
                    rsl.Message = "水洗标号不允许为空";
                    return rsl;
                }
                if (json.Property("proCode") == null || string.IsNullOrWhiteSpace(json["proCode"].ToString()))
                {
                    rsl.Message = "请先选择存货";
                    return rsl;
                }
                //if (json.Property("cusCode") == null || string.IsNullOrWhiteSpace(json["cusCode"].ToString()))
                //{
                //    rsl.Message = "请先选择客户";
                //    return rsl;
                //}
                if (json.Property("proColor") != null && !string.IsNullOrWhiteSpace(json["proColor"].ToString()))
                {
                    ys = json["proColor"].ToString();
                }
                if (json.Property("brand") != null && !string.IsNullOrWhiteSpace(json["brand"].ToString()))
                {
                    sb = json["brand"].ToString();
                }

                #endregion
                sxb.proCode = json["proCode"].ToString();
                sxb.proName = json["proName"].ToString();
                //sxb.cusCode = json["cusCode"].ToString();
                //sxb.cusName = json["cusName"].ToString();
                sxb.isDel = 0;
                sxb.proColor = ys;
                sxb.brand = sb;
                sxb.outBarcode = json["outBarcode"].ToString();
                oper = new OperateModel();
                string sql = "select top 1 * from fun_ShuiXiBiao_Info where isDel=0 and outBarcode='" + json["outBarcode"].ToString() + "'" +
                   " and proCode ='" + json["proCode"].ToString() + "' and proColor ='" + ys + "' and brand ='" + sb + "'";
                var qTable = cmd.GetDataTable(sql);
                if (json["id"].ToString() == "0" || string.IsNullOrWhiteSpace(json["id"].ToString()))
                {
                    if (qTable.Rows.Count > 0)
                    {
                        rsl.Message = "水洗标已存在相同存货信息：" + json["outBarcode"].ToString() + ","
                            + json["proName"].ToString() + "," + ys + "," + sb;
                        return rsl;
                    }
                    sxb.createtime = getNow();
                    sxb.createuser = userLogin.UserInfo().userCode;
                    oper.Types = OperateModel.OperateType.Add;
                }
                else
                {
                    if (qTable.Rows.Count > 0 && qTable.Rows[0]["id"].ToString() != json["id"].ToString())
                    {
                        rsl.Message = "水洗标已存在：" + json["outBarcode"].ToString() + "," + json["proName"].ToString() + "," + ys + ","
                            + sb;
                        return rsl;
                    }
                    sxb.id = int.Parse(json["id"].ToString());
                    oper.Conditions = "id";
                    oper.Types = OperateModel.OperateType.Edit;
                }
                oper.Data = sxb;
                operList.Add(oper);
                rsl = cmd.MoreUpdate(operList);

            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 删除水洗标号
        /// </summary>
        /// <param name="dataId"></param>
        /// <returns></returns>
        public ReturnResult DelShuiXiBiao(string dataId)
        {
            rsl = new ReturnResult();
            try
            {
                DbShuiXiBiao sxb = new DbShuiXiBiao();
                sxb.isDel = 1;
                sxb.delTime = getNow();
                sxb.delUser = userLogin.UserInfo().userCode;
                sxb.id = int.Parse(dataId);
                oper = new OperateModel();
                oper.Data = sxb;
                oper.Conditions = "id";
                oper.Types = OperateModel.OperateType.Edit;
                rsl = cmd.Edit(oper);
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 导出工艺单价模板
        /// </summary>
        /// <param name="dataId"></param>
        /// <returns></returns>
        public MemoryStream ExportDataExcel(string condition)
        {
            MemoryStream ms = null;
            try
            {
                if (string.IsNullOrWhiteSpace(condition))
                {
                    return ms;
                }
                var json = JsonConvert.DeserializeObject<JObject>(condition);
                var title = new string[] { };
                if (json.Property("title") != null && json["title"] != null)
                {
                    title = JsonConvert.DeserializeObject<string[]>(json["title"].ToString());
                }
                NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
                //添加一个sheet
                NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
                //给sheet1添加第一行的头部标题
                NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
                if (title != null && title.Length > 0)
                {
                    for (int i = 0; i < title.Length; i++)
                    {
                        row1.CreateCell(i).SetCellValue(title[i]);
                    }
                }
                ms = new System.IO.MemoryStream();
                book.Write(ms);
                ms.Seek(0, SeekOrigin.Begin);
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return ms;
        }

        /// <summary>
        /// 导入工序单价
        /// </summary>
        /// <param name="organizationId"></param>
        /// <returns></returns>
        public ReturnResult ImportExcel(HttpPostedFileBase file)
        {
            rsl = new ReturnResult();
            var temI = "";
            #region
            try
            {
                //HttpPostedFile file = HttpContext.Current.Request.Files[0];
                string FileName;
                string savePath;
                if (file == null || file.ContentLength <= 0)
                {
                    rsl.Message = "文件为空!";
                }
                else
                {
                    #region 将上传的文件存到固定地址
                    string filename = Path.GetFileName(file.FileName);
                    int filesize = file.ContentLength;//获取上传文件的大小单位为字节byte
                    string fileEx = System.IO.Path.GetExtension(filename);//获取上传文件的扩展名
                    string NoFileName = System.IO.Path.GetFileNameWithoutExtension(filename);//获取无扩展名的文件名
                    int Maxsize = 4000 * 1024;//定义上传文件的最大空间大小为4M
                    string FileType = ".xls,.xlsx";//定义上传文件的类型字符串

                    FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + NoFileName + fileEx;
                    if (!FileType.Contains(fileEx))
                    {
                        rsl.Message = ("文件类型不对，只能导入xls和xlsx格式的文件！");
                        return rsl;
                    }
                    if (filesize >= Maxsize)
                    {
                        rsl.Message = ("上传文件超过4M，不能上传！");
                        return rsl;
                    }

                    string path = HostingEnvironment.MapPath("~/files/");
                    if (!Directory.Exists(path))
                        Directory.CreateDirectory(path);//根据路径创建指定文件
                    savePath = Path.Combine(path, FileName);
                    file.SaveAs(savePath);
                    #endregion
                    //DataTable table = GetExcelData(savePath).Tables[0];   //读取excel内容
                    //DataTable table = ReadExcelToDataSet(savePath).Tables[0];   //读取excel内容
                    DataTable table = ReadExcelToDataTable(savePath);   //读取excel内容

                    string gxCode = "", proType = "";
                    List<string> list = new List<string>();
                    List<int> rows = new List<int>();

                    #region   对excel表内信息进行 工序编码重复验证 
                   
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        temI = i.ToString();
                        if (string.IsNullOrWhiteSpace(table.Rows[i]["工序编码"].ToString()))
                        {
                            rsl.Message = ("第" + (i + 1) + "行工序编码不能为空");
                            return rsl;
                        }
                        if (string.IsNullOrWhiteSpace(table.Rows[i]["工序名称"].ToString()))
                        {
                            rsl.Message = ("第" + (i + 1) + "行工序名称不能为空");
                            return rsl;
                        }
                        if (string.IsNullOrWhiteSpace(table.Rows[i]["合格工价"].ToString()) || Convert.ToDecimal(table.Rows[i]["合格工价"].ToString()) < 0)
                        {
                            rsl.Message = ("第" + (i + 1) + "行合格工价不能为空");
                            return rsl;
                        }
                        if (string.IsNullOrWhiteSpace(table.Rows[i]["不合格工价"].ToString()) || Convert.ToDecimal(table.Rows[i]["不合格工价"].ToString()) < 0)
                        {
                            rsl.Message = ("第" + (i + 1) + "行不合格工价不能为空");
                            return rsl;
                        }
                        //工序编码重复验证
                        DataRow[] dRows = table.Select("工序编码='" + table.Rows[i]["工序编码"].ToString() + "'");
                        if (dRows.Length > 1)
                        {
                            rsl.Message = ("当前EXCEl表中存在相同的工序编码：") + table.Rows[i]["工序编码"].ToString();
                            return rsl;
                        }
                        //去重
                        //dRows = table.Select("工序大类='" + table.Rows[i][0].ToString() + "' and [品 类]='" + table.Rows[i][1].ToString() +
                        //    "' and 工序编码='" + table.Rows[i][2].ToString() + "' and 合格工价='" + table.Rows[i][4].ToString() +
                        //    "' and 不合格工价='" + table.Rows[i][5].ToString() + "'");
                        //if (dRows.Length > 1)
                        //{
                        //    rows.Add(i);
                        //    continue;
                        //}
                    }
                    temI = "";
                    #endregion

                    #region  对excel表内信息进行工序大类、品类是否存在的验证 是否与已有工序重复验证  和添加操作
                    foreach (DataRow dr in table.Rows)
                    {
                        //判断是否有工序大类
                        string sql = "select * from fun_CommonData_Info where cName='" + dr["工序大类"].ToString() + "' and cType='GX' and status='Y' and isDel=0 ";
                        var sqlTable = cmd.GetDataTable(sql.ToString());
                        if (sqlTable.Rows.Count > 0)
                        {
                            gxCode = sqlTable.Rows[0]["cCode"].ToString();
                        }
                        else
                        {
                            rsl.Message = "当前系统中不存在此工序大类：" + dr["工序大类"].ToString();
                            return rsl;
                        }

                        //判断是否有品类
                        sql = "select * from fun_CommonData_Info where cName='" + dr["品类"].ToString() + "' and cType='SCTYPE' and status='Y' and isDel=0 ";
                        sqlTable = cmd.GetDataTable(sql.ToString());
                        if (sqlTable.Rows.Count > 0)
                        {
                            proType = sqlTable.Rows[0]["cCode"].ToString();
                        }
                        else
                        {
                            rsl.Message = "当前系统中不存在此品类：" + dr["品类"].ToString();
                            return rsl;
                        }
                        //判断工序是否重复
                        sql = "select * from fun_GxPrice_info where cgxCode='" + dr["工序编码"].ToString() + "' and isDel=0 ";
                        sqlTable = cmd.GetDataTable(sql.ToString());
                        if (sqlTable.Rows.Count > 0)
                        {
                            rsl.Message = "当前系统中已存在此工序：" + dr["工序编码"].ToString();
                            return rsl;
                        }

                        sql = "insert into fun_GxPrice_info(cgxCode,cgxName,yPrice,nPrice,gxCode,proType,createtime,createuser,isDel) " +
                            "values('" + dr["工序编码"].ToString() + "','" + dr["工序名称"].ToString() + "','" +
                            dr["合格工价"].ToString() + "','" + dr["不合格工价"].ToString() + "','" +
                            gxCode + "','" + proType + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" +
                            userLogin.UserInfo().userCode + "',0)";
                        list.Add(sql);
                    }
                    #endregion
                    if (list.Count<1) {
                        rsl.Message = "未获取到导入数据";
                        return rsl;
                    }
                    rsl = cmd.MoreUpdate(list);

                }//else end
            }
            catch (Exception ex)
            {
                rsl.Message = "第" + ( temI+ 1) + "行" + ex.Message;
                return rsl;
            }
            return rsl;
            #endregion

        }//function end

        /// <summary>
        /// 导入工艺
        /// </summary>
        /// <param name="organizationId"></param>
        /// <returns></returns>
        public ReturnResult ImportGXExcel(HttpPostedFileBase file)
        {
            rsl = new ReturnResult();
            var temI = 0;
            #region
            try
            {
                string FileName;
                string savePath;
                if (file == null || file.ContentLength <= 0)
                {
                    rsl.Message = "文件为空!";
                }
                else
                {
                    #region 将上传的文件存到固定地址
                    string filename = Path.GetFileName(file.FileName);
                    int filesize = file.ContentLength;//获取上传文件的大小单位为字节byte
                    string fileEx = System.IO.Path.GetExtension(filename);//获取上传文件的扩展名
                    string NoFileName = System.IO.Path.GetFileNameWithoutExtension(filename);//获取无扩展名的文件名
                    int Maxsize = 4000 * 1024;//定义上传文件的最大空间大小为4M
                    string FileType = ".xls,.xlsx";//定义上传文件的类型字符串

                    FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + NoFileName + fileEx;
                    if (!FileType.Contains(fileEx))
                    {
                        rsl.Message = ("文件类型不对，只能导入xls和xlsx格式的文件！");
                        return rsl;
                    }
                    if (filesize >= Maxsize)
                    {
                        rsl.Message = ("上传文件超过4M，不能上传！");
                        return rsl;
                    }

                    string path = HostingEnvironment.MapPath("~/files/");
                    if (!Directory.Exists(path))
                        Directory.CreateDirectory(path);//根据路径创建指定文件
                    savePath = Path.Combine(path, FileName);
                    file.SaveAs(savePath);
                    #endregion
                    //DataTable table = GetExcelData(savePath).Tables[0];   //读取excel内容
                    //DataTable table = ReadExcelToDataSet(savePath).Tables[0];   //读取excel内容
                    DataTable table = ReadExcelToDataTable(savePath);   //读取excel内容

                    #region 相关表数据获取
                    string sql = "select * from fun_CommonData_Info where cType='SCTYPE' and status='Y' and isDel=0 ";
                    var plTable = cmd.GetDataTable(sql.ToString());  //品类表

                    sql="select gyCode from fun_products_gx ";
                    var gyDt = cmd.GetDataTable(sql.ToString()); //工艺表

                    sql = "select p.*,c.orderNum from fun_GxPrice_info p " +
                        "left join fun_CommonData_Info c on c.cCode = p.gxCode and c.cType = 'GX' and status = 'Y' and c.isDel = 0" +
                        "where p.isDel = 0";
                    var sqlTable = cmd.GetDataTable(sql.ToString());  //工序单价表

                    #endregion

                    string proType = "";
                    List<string> list = new List<string>();
                    List<int> rows = new List<int>();

                    #region  对excel表内信息进行品类是否存在的验证、工艺名称重复验证 和添加操作
                    var ir = 0;
                    var messList = new List<string>();
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        var dr = table.Rows[i];
                        
                        ir++;
                        temI = ir;
                        var temgyCode = "GY" + DateTime.Now.ToString("yyyyMMddHHmmss") + ir;
                        var messge = "";
                        if (string.IsNullOrWhiteSpace(table.Rows[i]["品类编码"].ToString()))
                        {
                            messge = ("第" + (temI + 1) + "行品类编码不能为空");
                            messList.Add(messge);
                            continue;
                        }
                        if (string.IsNullOrWhiteSpace(table.Rows[i]["品类名称"].ToString()))
                        {
                            messge = ("第" + (temI + 1) + "行品类名称不能为空");
                            messList.Add(messge);
                            continue;
                        }
                        if (string.IsNullOrWhiteSpace(table.Rows[i]["工艺名称"].ToString()))
                        {
                            rsl.Message = ("第" + (temI + 1) + "行工艺名称不能为空");
                            messList.Add(messge);
                            continue;
                        }
                        //工艺名称重复验证
                        DataRow[] dRows = table.Select("工艺名称='" + table.Rows[i]["工艺名称"].ToString() + "'");
                        if (dRows.Length > 1)
                        {
                            messge = ("第" + (temI + 1) + "行，当前EXCEl表中存在相同的工艺名称：") + table.Rows[i]["工艺名称"].ToString();
                            messList.Add(messge);
                            continue;
                        }
                        //判断是否有品类
                        var row= plTable.Select("cCode='" + dr["品类编码"].ToString() + "'");
                        if (row.Length > 0)
                        {
                            proType = row[0]["cCode"].ToString();
                        }
                        else
                        {
                            messge = "第" + (temI + 1) + "行，当前系统中不存在此品类：" + dr["品类编码"].ToString();
                            messList.Add(messge);
                            continue;
                        }
                        messge ="";
                        var names = dr["工艺名称"].ToString().Split('-');
                        if (!string.IsNullOrWhiteSpace(dr["工艺编码"].ToString().Trim())) {
                            temgyCode = dr["工艺编码"].ToString().Trim();
                            row = gyDt.Select("gyCode='" + temgyCode + "'");
                            if (row.Length> 0) {
                                messge = "第" + (temI + 1) + "行，当前系统中已存在此工艺编码：" + temgyCode;
                                messList.Add(messge);
                                continue;
                            }
                        }

                        #region  新增
                        int fgxOrder = 0;
                        Double num = 0;
                        var orders = new Dictionary<string, double>();
                        foreach (var s in names)
                        {
                            row = sqlTable.Select("cgxName='" + s.Trim() + "'");
                            if (row.Length < 1)
                            {
                                messge += s+"：工序在工序单价中不存在";
                                continue;
                            }
                            else
                            {
                                fgxOrder = int.Parse(row[0]["orderNum"].ToString());
                                if (orders.ContainsKey(row[0]["gxCode"].ToString()))
                                {
                                    orders[row[0]["gxCode"].ToString()]++;
                                }
                                else
                                {
                                    orders.Add(row[0]["gxCode"].ToString(),1);
                                }
                                num = fgxOrder + (orders[row[0]["gxCode"].ToString()] / 1000);
                            }


                            sql = "insert into fun_products_gx(proCode,gxCode,gxOrder,dType,createtime,createuser,isChild,gyCode,gyName) " +
                           "values('" + dr["品类编码"].ToString() + "','" + sqlTable.Rows[0]["cgxCode"].ToString() + "','"+num+"','pType','" +
                            DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" +userLogin.UserInfo().userCode + "',1,'"+
                            temgyCode + "','"+ dr["工艺名称"].ToString() + "')";
                            list.Add(sql);
                        }
                        if (!string.IsNullOrWhiteSpace(messge)) {
                            messge = "第" + (ir + 1) + "行；"+ messge;
                            messList.Add(messge);
                        }

                        #endregion
                    }
                    var messageS = JsonConvert.SerializeObject(messList);
                    if (messList!=null&&messList.Count>0) {
                        rsl.Message = "错误如下："+"\n"+ messageS;
                        return rsl;
                    }
                    #endregion
                    if (list.Count < 1)
                    {
                        rsl.Message = "未获取到导入数据";
                        return rsl;
                    }
                    rsl = cmd.MoreUpdate(list);

                }
            }
            catch (Exception ex)
            {
                rsl.Message = "第" + (temI + 1) + "行" + ex.Message;
                return rsl;
            }
            return rsl;
            #endregion

        }//function end

        /// <summary>
        /// 导入工装车档案
        /// </summary>
        /// <param name="organizationId"></param>
        /// <returns></returns>
        public ReturnResult ImportCarExcel(HttpPostedFileBase file)
        {
            rsl = new ReturnResult();
            var temI = 0;
            #region
            try
            {
                string FileName;
                string savePath;
                if (file == null || file.ContentLength <= 0)
                {
                    rsl.Message = "文件为空!";
                }
                else
                {
                    #region 将上传的文件存到固定地址
                    string filename = Path.GetFileName(file.FileName);
                    int filesize = file.ContentLength;//获取上传文件的大小单位为字节byte
                    string fileEx = System.IO.Path.GetExtension(filename);//获取上传文件的扩展名
                    string NoFileName = System.IO.Path.GetFileNameWithoutExtension(filename);//获取无扩展名的文件名
                    int Maxsize = 4000 * 1024;//定义上传文件的最大空间大小为4M
                    string FileType = ".xls,.xlsx";//定义上传文件的类型字符串

                    FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + NoFileName + fileEx;
                    if (!FileType.Contains(fileEx))
                    {
                        rsl.Message = ("文件类型不对，只能导入xls和xlsx格式的文件！");
                        return rsl;
                    }
                    if (filesize >= Maxsize)
                    {
                        rsl.Message = ("上传文件超过4M，不能上传！");
                        return rsl;
                    }

                    string path = HostingEnvironment.MapPath("~/files/");
                    if (!Directory.Exists(path))
                        Directory.CreateDirectory(path);//根据路径创建指定文件
                    savePath = Path.Combine(path, FileName);
                    file.SaveAs(savePath);
                    #endregion

                    DataTable table = ReadExcelToDataTable(savePath);   //读取excel内容

                    string proType = "";
                    List<string> list = new List<string>();
                    List<int> rows = new List<int>();

                    #region  对excel表内信息进行编码是否重复的验证 和添加操作
                    var ir = 0;
                    var messList = new List<string>();
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        var dr = table.Rows[i];
                        ir++;
                        temI = ir;
                        var messge = "";
                        if (string.IsNullOrWhiteSpace(table.Rows[i]["编码"].ToString()))
                        {
                            messge = ("第" + (temI + 1) + "行编码不能为空");
                            messList.Add(messge);
                            continue;
                        }
                        if (string.IsNullOrWhiteSpace(table.Rows[i]["名称"].ToString()))
                        {
                            messge = ("第" + (temI + 1) + "行名称不能为空");
                            messList.Add(messge);
                            continue;
                        }
                        //EXCEl表内编码重复验证
                        DataRow[] dRows = table.Select("编码='" + table.Rows[i]["编码"].ToString() + "'");
                        if (dRows.Length > 1)
                        {
                            messge = ("第" + (temI + 1) + "行，当前EXCEl表中存在相同的编码：") + table.Rows[i]["编码"].ToString();
                            messList.Add(messge);
                            continue;
                        }

                        //判断是否与档案内编码重复
                        var sql = "select * from fun_Cars_info where cCode='" + dr["编码"].ToString() + "' and isdel=0 ";
                        var sqlTable = cmd.GetDataTable(sql.ToString());
                        if (sqlTable.Rows.Count > 0)
                        {
                            rsl.Message = "当前档案中已存在此编码：" + dr["编码"].ToString();
                            return rsl;
                        }

                        sql = "insert into fun_Cars_info(cCode,cName,createtime,createuser,isdel) " +
                           "values('" + dr["编码"].ToString() + "','" + dr["名称"].ToString() + "','" +
                           DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" +
                           userLogin.UserInfo().userCode + "',0)";
                        list.Add(sql);

                    }
                    var messageS = JsonConvert.SerializeObject(messList);
                    if (messList != null && messList.Count > 0)
                    {
                        rsl.Message = "错误如下：" + "\n" + messageS;
                        return rsl;
                    }
                    #endregion
                    if (list.Count < 1)
                    {
                        rsl.Message = "未获取到导入数据";
                        return rsl;
                    }
                    rsl = cmd.MoreUpdate(list);

                }//else ends
            }
            catch (Exception ex)
            {
                rsl.Message = "第" + (temI + 1) + "行" + ex.Message;
                return rsl;
            }
            return rsl;
            #endregion

        }//function end

        /// <summary>
        /// 客户分配
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public ReturnResult CuUserInfo(string pageIndex, string pageSize, ref string pageCount, string condition,string where)
        {
            rsl = new ReturnResult();
            try
            {
                var json = JsonConvert.DeserializeObject<JObject>(condition);//员工
                StringBuilder sb = new StringBuilder();
                sb.Append("select cm.cuCode, cm.cuName, u.userCode, u.userName, g.createtime, cm.dataType, cm.isDel, cm.status, g.dType, g.cmType ");
                sb.Append("FROM (SELECT  id, cuCode, cuName, baseCode, cuType, status, createuser, createtime, isDel, delDate, delUser, isSync,");
                sb.Append("batchCode, dataType, arddress,recArddress, phone FROM  fun_Customs_info WHERE   (dataType = 'Cu')) AS cm  ");
                sb.Append("LEFT OUTER JOIN dbo.fun_Users_gangwei AS g ON cm.cuCode = g.groupCode AND g.isdel = 0 AND g.dType = 'CuMan' and cmType='"+where+"' ");
                sb.Append("LEFT OUTER JOIN  dbo.sys_users_info AS u ON g.userCode = u.userCode AND u.isDel = 0 AND u.status = 'Y' ");
                var tableName = sb.ToString();
                #region where
                sb.Clear();
                sb.Append(" isdel=0 and status='Y' ");//dType ='CuMan' and 
                foreach (JProperty obj in json.Properties())
                {
                    if (!string.IsNullOrWhiteSpace(obj.Value.ToString()))
                    {
                        if (obj.Name == "userCode")
                        {
                            //sb.Append(obj.Name + "='" + obj.Value.ToString() + "' ");
                            continue;
                        }
                        else if (obj.Name == "userCodes")
                        {
                            var arr = obj.Value.ToString().Split(',');
                            string gcodes = "";
                            foreach (string s in arr)
                            {
                                if (!string.IsNullOrWhiteSpace(s))
                                {
                                    gcodes += s + ",";
                                }
                            }
                            sb.Append("and userCode in(" + gcodes.TrimEnd(',') + ") ");
                        }
                        else
                        {
                            sb.Append("and "+obj.Name + " like '%" + obj.Value.ToString() + "%' ");
                        }
                    }
                }
                #endregion
                var sqlWhere = sb.ToString();
                var pageNumber = "0";  //总页数
                //var list = cmd.PageList("V_CuManager", pageIndex, pageSize, sb.ToString(), "userCode desc", ref pageCount);
                var list = cmd.PageTableList(tableName, pageIndex, pageSize, sqlWhere, "userCode desc", ref pageCount, ref pageNumber);

                //rsl.Data = list;
                rsl.Data = cmd.TableToDictionary(list);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 仓库管理员分配
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public ReturnResult WHUserInfo(string pageIndex, string pageSize, ref string pageCount, string condition, string where)
        {
            rsl = new ReturnResult();
            try
            {
                var json = JsonConvert.DeserializeObject<JObject>(condition);//员工
                StringBuilder sb = new StringBuilder();
                sb.Append("select wh.houseCode, wh.houseName, u.userCode, u.userName, g.createtime, wh.isDel, wh.status, g.dType ");
                sb.Append("FROM fun_WareHouse_Info AS wh ");
                sb.Append("LEFT OUTER JOIN dbo.fun_Users_gangwei AS g ON wh.houseCode = g.groupCode AND g.isdel = 0 AND g.dType = 'WH' ");
                sb.Append("LEFT OUTER JOIN  dbo.sys_users_info AS u ON g.userCode = u.userCode AND u.isDel = 0 AND u.status = 'Y' ");
                var tableName = sb.ToString();
                #region where
                sb.Clear();
                sb.Append(" isdel=0 and status='open' ");
                foreach (JProperty obj in json.Properties())
                {
                    if (!string.IsNullOrWhiteSpace(obj.Value.ToString()))
                    {
                        if (obj.Name == "userCode")
                        {
                            //sb.Append(obj.Name + "='" + obj.Value.ToString() + "' ");
                            continue;
                        }
                        else if (obj.Name == "userCodes")
                        {
                            var arr = obj.Value.ToString().Split(',');
                            string gcodes = "";
                            foreach (string s in arr)
                            {
                                if (!string.IsNullOrWhiteSpace(s))
                                {
                                    gcodes += s + ",";
                                }
                            }
                            sb.Append("and userCode in(" + gcodes.TrimEnd(',') + ") ");
                        }
                        else
                        {
                            sb.Append("and " + obj.Name + " like '%" + obj.Value.ToString() + "%' ");
                        }
                    }
                }
                #endregion
                var sqlWhere = sb.ToString();
                var pageNumber = "0";  //总页数
                var list = cmd.PageTableList(tableName, pageIndex, pageSize, sqlWhere, "userCode desc", ref pageCount, ref pageNumber);

                rsl.Data = cmd.TableToDictionary(list);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

         /// <summary>
        /// 客户发货管理分配
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public ReturnResult CuFHInfo(string pageIndex, string pageSize, ref string pageCount, string condition, string where)
        {
            rsl = new ReturnResult();
            try
            {
                var json = JsonConvert.DeserializeObject<JObject>(condition);
                StringBuilder sb = new StringBuilder();
                sb.Append("select c.cuCode,c.cuName,c.baseCode,m.*,w.houseName wareName ");
                sb.Append("FROM fun_Customs_info c ");
                sb.Append("left join fun_CuWhMatch_info m on c.cuCode = m.cusCode and c.dataType='Cu' and c.isDel = 0 and c.status = 'Y' and m.isdel = 0 ");
                sb.Append("left join fun_WareHouse_Info w on w.houseCode = m.wareCode and c.baseCode = w.baseCode and w.isDel = 0 and w.status = 'open' ");
                sb.Append("left join fun_CommonData_Info p on p.cCode = m.positionCode and specFile = c.baseCode and cType = 'WP' and p.isDel = '0' and p.status = 'Y' ");
                var tableName = sb.ToString();
                #region where
                sb.Clear();
                sb.Append(" baseCode='"+userLogin.UserInfo().baseCode+"' ");
                foreach (JProperty obj in json.Properties())
                {
                    if (!string.IsNullOrWhiteSpace(obj.Value.ToString()))
                    {
                        if (obj.Name == "cuCode")
                        {
                            if(json["cuCodes"]!=null && !string.IsNullOrWhiteSpace(json["cuCodes"].ToString()))
                            {
                                continue;
                            }
                            sb.Append("and cuCode like '%" + obj.Value.ToString() + "%' ");

                        }
                        else if (obj.Name == "cuCodes")
                        {
                            var arr = obj.Value.ToString().Split(',');
                            string gcodes = "";
                            foreach (string s in arr)
                            {
                                if (!string.IsNullOrWhiteSpace(s))
                                {
                                    gcodes += s + ",";
                                }
                            }
                            sb.Append("and cuCode in(" + gcodes.TrimEnd(',') + ") ");
                        }
                        else
                        {
                            sb.Append("and " + obj.Name + " like '%" + obj.Value.ToString() + "%' ");
                        }
                    }
                }
                #endregion
                var sqlWhere = sb.ToString();
                var pageNumber = "0";  //总页数
                var list = cmd.PageTableList(tableName, pageIndex, pageSize, sqlWhere, " wareCode desc, positionCode desc", ref pageCount, ref pageNumber);

                rsl.Data = cmd.TableToDictionary(list);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 获取员工
        /// </summary>
        /// <returns></returns>
        public ReturnResult getUsers(string userCode)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("select userCode,userName from sys_users_info where");
                sb.Append(" isdel=0  and status='Y' ");
                if (!string.IsNullOrWhiteSpace(userCode))
                {
                    sb.Append("and userCode like '%" + userCode + "%' ");
                }
                var table = cmd.GetDataTable(sb.ToString());
                if (table.Rows.Count > 0)
                {
                    rsl.Data = cmd.TableToDictionary(table);
                    rsl.Result = true;
                }
                else
                {
                    List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                    rsl.Result = true;
                    rsl.Data = list;
                    rsl.Message = "没有数据";
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 添加客户管理员工
        /// </summary>
        /// <param name="userCode"></param>
        /// <param name="cuCodes"></param>
        /// <returns></returns>
        public ReturnResult AddCuManager(string userCode, string cuCodes,string type )
        {
            rsl = new ReturnResult();
            operList = new List<OperateModel>();
            try
            {
                if (string.IsNullOrWhiteSpace(cuCodes))
                {
                    rsl.Message = "没有选择客户信息";
                    return rsl;
                }
                if (string.IsNullOrWhiteSpace(userCode))
                {
                    rsl.Message = "人员信息不允许为空";
                    return rsl;
                }
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from fun_Users_gangwei where isdel=0 and dType='CuMan' and cmType='"+type+"'");
                var table = cmd.GetDataTable(sb.ToString());
                var cuArr = cuCodes.Split(',');
                foreach (string cu in cuArr)
                {
                    if (!string.IsNullOrWhiteSpace(cu))
                    {
                        var dr = table.Select("groupCode='" + cu + "'");
                        if (dr.Length > 0)
                        {
                            rsl.Message = string.Format("该客户已由其他员工负责:{0}", cu);
                            return rsl;
                        }
                        else
                        {
                            #region 添加信息
                            DbUserPosition up = new DbUserPosition();
                            up.userCode = userCode;
                            up.groupCode = cu;
                            up.createtime = getNow();
                            up.isdel = 0;
                            up.cmType = type;
                            up.dType = "CuMan";
                            up.createuser = userLogin.UserInfo().userCode;
                            oper = new OperateModel();
                            oper.Data = up;
                            oper.Types = OperateModel.OperateType.Add;
                            operList.Add(oper);
                            #endregion
                        }
                    }
                }
                if (operList.Count > 0)
                {
                    rsl = cmd.MoreUpdate(operList);
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 删除客户管理员工
        /// </summary>
        /// <param name="cuCodes"></param>
        /// <returns></returns>
        public ReturnResult DelCuManager(string cuCodes,string type)
        {
            rsl = new ReturnResult();
            operList = new List<OperateModel>();
            try
            {
                if (string.IsNullOrWhiteSpace(cuCodes))
                {
                    rsl.Message = "没有客户信息";
                    return rsl;
                }
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from fun_Users_gangwei where isdel=0 and dType='CuMan' and cmType='" + type + "'");
                var table = cmd.GetDataTable(sb.ToString());
                var cuArr = cuCodes.Split(',');
                foreach (string cu in cuArr)
                {
                    if (!string.IsNullOrWhiteSpace(cu))
                    {
                        var dr = table.Select("groupCode='" + cu + "'");
                        if (dr.Length < 1)
                        {
                            rsl.Message = string.Format("该客户无需删除负责员工信息:{0}", cu);
                            return rsl;
                        }
                        else
                        {
                            #region 删除信息
                            DbUserPosition up = new DbUserPosition();
                            up.groupCode = cu;
                            up.isdel = 1;
                            up.cmType = type;
                            up.delDate = getNow();
                            up.deluser = userLogin.UserInfo().userCode;
                            oper = new OperateModel();
                            oper.Data = up;
                            oper.Types = OperateModel.OperateType.Edit;
                            oper.Conditions = "groupCode,cmType";
                            operList.Add(oper);
                            #endregion
                        }
                    }
                }
                if (operList.Count > 0)
                {
                    rsl = cmd.MoreUpdate(operList);
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 添加库管
        /// </summary>
        /// <param name="userCode"></param>
        /// <param name="cuCodes"></param>
        /// <returns></returns>
        public ReturnResult AddWHManager(string userCode, string houseCodes)
        {
            rsl = new ReturnResult();
            operList = new List<OperateModel>();
            try
            {
                if (string.IsNullOrWhiteSpace(houseCodes))
                {
                    rsl.Message = "没有选择仓库信息";
                    return rsl;
                }
                if (string.IsNullOrWhiteSpace(userCode))
                {
                    rsl.Message = "人员信息不允许为空";
                    return rsl;
                }
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from fun_Users_gangwei where isdel=0 and dType='WH'");
                var table = cmd.GetDataTable(sb.ToString());
                var whArr = houseCodes.Split(',');
                foreach (string wh in whArr)
                {
                    if (!string.IsNullOrWhiteSpace(wh))
                    {
                        var dr = table.Select("groupCode='" + wh + "'");
                        if (dr.Length > 0)
                        {
                            rsl.Message = string.Format("该仓库已由其他员工负责:{0}", wh);
                            return rsl;
                        }
                        else
                        {
                            #region 添加信息
                            DbUserPosition up = new DbUserPosition();
                            up.userCode = userCode;
                            up.groupCode = wh;
                            up.createtime = getNow();
                            up.isdel = 0;
                            up.dType = "WH";
                            up.createuser = userLogin.UserInfo().userCode;
                            oper = new OperateModel();
                            oper.Data = up;
                            oper.Types = OperateModel.OperateType.Add;
                            operList.Add(oper);
                            #endregion
                        }
                    }
                }
                if (operList.Count > 0)
                {
                    rsl = cmd.MoreUpdate(operList);
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 删除库管
        /// </summary>
        /// <param name="cuCodes"></param>
        /// <returns></returns>
        public ReturnResult DelWHManager(string houseCodes)
        {
            rsl = new ReturnResult();
            operList = new List<OperateModel>();
            try
            {
                if (string.IsNullOrWhiteSpace(houseCodes))
                {
                    rsl.Message = "没有仓库信息";
                    return rsl;
                }
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from fun_Users_gangwei where isdel=0 and dType='WH' ");
                var table = cmd.GetDataTable(sb.ToString());
                var whArr = houseCodes.Split(',');
                foreach (string wh in whArr)
                {
                    if (!string.IsNullOrWhiteSpace(wh))
                    {
                        var dr = table.Select("groupCode='" + wh + "'");
                        if (dr.Length < 1)
                        {
                            rsl.Message = string.Format("该仓库无需删除负责员工信息:{0}", wh);
                            return rsl;
                        }
                        else
                        {
                            #region 删除信息
                            DbUserPosition up = new DbUserPosition();
                            up.groupCode = wh;
                            up.isdel = 1;
                            up.dType = "WH";
                            up.delDate = getNow();
                            up.deluser = userLogin.UserInfo().userCode;
                            oper = new OperateModel();
                            oper.Data = up;
                            oper.Types = OperateModel.OperateType.Edit;
                            oper.Conditions = "groupCode,dType";
                            operList.Add(oper);
                            #endregion
                        }
                    }
                }
                if (operList.Count > 0)
                {
                    rsl = cmd.MoreUpdate(operList);
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 添加客户发货仓库货位
        /// </summary>
        /// <returns></returns>
        public ReturnResult AddFHManager(string wareCode, string positionCode, string cuCodes)
        {
            rsl = new ReturnResult();
            operList = new List<OperateModel>();
            try
            {
                if (string.IsNullOrWhiteSpace(wareCode))
                {
                    rsl.Message = "没有选择仓库信息";
                    return rsl;
                }
                if (string.IsNullOrWhiteSpace(cuCodes))
                {
                    rsl.Message = "客户信息不允许为空";
                    return rsl;
                }
                
                var cus = cuCodes.Split(',');
                foreach (string cu in cus)
                {
                    if (!string.IsNullOrWhiteSpace(cu))
                    {
                        #region 添加信息
                        DbCuFHWarePosition fh = new DbCuFHWarePosition();
                        fh.cusCode = cu;
                        fh.wareCode = wareCode;
                        fh.positionCode = positionCode;
                        fh.createtime = getNow();
                        fh.isdel = 0;
                        fh.createuser = userLogin.UserInfo().userCode;
                        oper = new OperateModel();
                        oper.Data = fh;
                        oper.Types = OperateModel.OperateType.Add;
                        operList.Add(oper);
                        #endregion
                    }
                }
                if (operList.Count > 0)
                {
                    rsl = cmd.MoreUpdate(operList);
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 删除客户发货仓库货位信息
        /// </summary>
        /// <param name="cuCodes"></param>
        /// <returns></returns>
        public ReturnResult DelFHManager(string cuCodes,string ids)
        {
            rsl = new ReturnResult();
            var List = new List<string>();
            try
            {
                if (string.IsNullOrWhiteSpace(cuCodes))
                {
                    rsl.Message = "没有客户信息";
                    return rsl;
                }

                StringBuilder sb = new StringBuilder();
                sb.Append("update fun_CuWhMatch_info set isdel=1,deluser='" + userLogin.UserInfo().userCode + "',deltime='" + getNow() + "' ");
                sb.Append("where id in ("+ids.TrimEnd(',')+") ");
                List.Add(sb.ToString());
              
                if (List.Count > 0)
                {
                    rsl = cmd.MoreUpdate(List);
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 删除父工序数据方法
        /// </summary>
        /// <param name="dataId">数据id</param>
        /// <returns></returns>
        public ReturnResult DelFGXData(string dataId)
        {
            rsl = new ReturnResult();
            try
            {
                oper = new OperateModel();
                DbCommonData data = new DbCommonData();
                data.id = int.Parse(dataId);
                data.isDel = 1;
                data.delDate = getNow();
                data.delUser = userLogin.UserInfo().userCode;
                oper.Data = data;
                oper.Types = OperateModel.OperateType.Edit;
                oper.Conditions = "id";
                rsl = cmd.Edit(oper);
                //StringBuilder sb = new StringBuilder();
                //sb.Append("seleCt count(*) count from fun_CommonData_Info comm ");
                //sb.Append("inner join fun_GxPrice_info gx on gx.gxCode = comm.cCode where comm.id="+dataId);
                //var cgxTable = cmd.GetDataTable(sb.ToString());
                //if (Convert.ToInt32(cgxTable.Rows[0][0]) > 0) {
                //    rsl.Message = "此大类已配置子工序，请先删除子工序。";
                //    return rsl;
                //}
                //else
                //{

                //}
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }


        /// <summary>
        /// 工装车档案
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageCount"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public ReturnResult getCarsInfo(string pageIndex, string pageSize, ref string pageCount, string condition)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(" isdel=0 ");
                sb = CreateSelectCondition(sb, condition);
                var list = cmd.PageList("fun_Cars_Info", pageIndex, pageSize, sb.ToString(), "id desc", ref pageCount);

                var dic = new Dictionary<string, string>();
                dic["isdel"] = "0";
                dic["id"] = "0";
                dic["cCode"] = "";
                dic["cName"] = "";
                dic["memo"] = "";

                list.Add(dic);
                rsl.Data = list;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 机台档案
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageCount"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public ReturnResult getMachinesInfo(string pageIndex, string pageSize, ref string pageCount, string condition)
        {
            rsl = new ReturnResult();
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(" isdel=0 ");
                sb = CreateSelectCondition(sb, condition);
                var list = cmd.PageList("V_machine_info", pageIndex, pageSize, sb.ToString(), "id desc", ref pageCount);

                var dic = new Dictionary<string, string>();
                dic["isdel"] = "0";
                dic["id"] = "0";
                dic["mTypeName"] = "";

                list.Add(dic);
                rsl.Data = list;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 保存工装车信息
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public ReturnResult UpdateCarsInfo(string datas)
        {
            rsl = new ReturnResult();
            operList = new List<OperateModel>();
            try
            {
                var json = JsonConvert.DeserializeObject<JObject>(datas);
                DbCars c = new DbCars();
                #region 防空值
                if (json.Property("cCode") == null || string.IsNullOrWhiteSpace(json["cCode"].ToString()))
                {
                    rsl.Message = "车编码不允许为空";
                    return rsl;
                }
                if (json.Property("cName") == null || string.IsNullOrWhiteSpace(json["cName"].ToString()))
                {
                    rsl.Message = "车名称不允许为空";
                    return rsl;
                }

                #endregion
                
                c.cName = json["cName"].ToString();
                c.isDel = 0;
                c.memo = json["memo"].ToString();
                oper = new OperateModel();

                string sql = "select top 1 * from fun_Cars_Info where  cCode='" + json["cCode"].ToString() + "'";  //isdel = 0 and
                var qTable = cmd.GetDataTable(sql);
                if (json["id"].ToString() == "0" || string.IsNullOrWhiteSpace(json["id"].ToString()))
                {
                    #region 新增
                    c.cCode = json["cCode"].ToString();
                    if (qTable.Rows.Count > 0)
                    {
                        rsl.Message = "车编码重复：" + json["cCode"].ToString() ;
                        return rsl;
                    }
                    c.createtime = getNow();
                    c.createuser = userLogin.UserInfo().userCode;
                    oper.Types = OperateModel.OperateType.Add;
                    #endregion
                }
                else
                {
                    #region 修改
                    if (qTable.Rows.Count > 0 && qTable.Rows[0]["id"].ToString() != json["id"].ToString())
                    {
                        rsl.Message = "车编码重复：" + json["cCode"].ToString() ;
                        return rsl;
                    }
                    c.id = int.Parse(json["id"].ToString());
                    oper.Conditions = "id";
                    oper.Types = OperateModel.OperateType.Edit;
                    #endregion
                }

                oper.Data = c;
                operList.Add(oper);
                rsl = cmd.MoreUpdate(operList);

            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 删除工装车信息
        /// </summary>
        /// <param name="dataId"></param>
        /// <returns></returns>
        public ReturnResult DelCarsInfo(string dataId)
        {
            rsl = new ReturnResult();
            try
            {
                DbCars c = new DbCars();
                c.isDel = 1;
                c.deltime = getNow();
                c.delUser = userLogin.UserInfo().userCode;
                c.id = int.Parse(dataId);
                oper = new OperateModel();
                oper.Data = c;
                oper.Conditions = "id";
                oper.Types = OperateModel.OperateType.Edit;
                rsl = cmd.Edit(oper);
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 保存机台信息
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public ReturnResult UpdateMachinesInfo(string datas)
        {
            rsl = new ReturnResult();
            operList = new List<OperateModel>();
            try
            {
                var json = JsonConvert.DeserializeObject<JObject>(datas);
                DbMachines m = new DbMachines();
                #region 防空值
                if (json.Property("mCode") == null || string.IsNullOrWhiteSpace(json["mCode"].ToString()))
                {
                    rsl.Message = "机台编码不允许为空";
                    return rsl;
                }
                if (json.Property("mName") == null || string.IsNullOrWhiteSpace(json["mName"].ToString()))
                {
                    rsl.Message = "机台名称不允许为空";
                    return rsl;
                } 
                if (json.Property("mType") == null || string.IsNullOrWhiteSpace(json["mType"].ToString()))
                {
                    rsl.Message = "机台类型不允许为空";
                    return rsl;
                }

                #endregion
                
                m.mName = json["mName"].ToString();
                m.isDel = 0;
                m.mType = json["mType"].ToString();
                oper = new OperateModel();

                string sql = "select top 1 * from fun_machine_info where mCode='" + json["mCode"].ToString() + "'";   //isdel=0 and 
                var qTable = cmd.GetDataTable(sql);
                if (json["id"].ToString() == "0" || string.IsNullOrWhiteSpace(json["id"].ToString()))
                {
                    #region 新增
                    m.mCode = json["mCode"].ToString();
                    if (qTable.Rows.Count > 0)
                    {
                        rsl.Message = "机台编码重复：" + json["mCode"].ToString();
                        return rsl;
                    }
                    m.createtime = getNow();
                    m.createuser = userLogin.UserInfo().userCode;
                    oper.Types = OperateModel.OperateType.Add;
                    #endregion
                }
                else
                {
                    #region 修改
                    if (qTable.Rows.Count > 0 && qTable.Rows[0]["id"].ToString() != json["id"].ToString())
                    {
                        rsl.Message = "机台编码重复：" + json["mCode"].ToString();
                        return rsl;
                    }
                    m.id = int.Parse(json["id"].ToString());
                    oper.Conditions = "id";
                    oper.Types = OperateModel.OperateType.Edit;
                    #endregion
                }

                oper.Data = m;
                operList.Add(oper);
                rsl = cmd.MoreUpdate(operList);

            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 删除机台信息
        /// </summary>
        /// <param name="dataId"></param>
        /// <returns></returns>
        public ReturnResult DelMachinesInfo(string dataId)
        {
            rsl = new ReturnResult();
            try
            {
                DbMachines m = new DbMachines();
                m.isDel = 1;
                m.delMsg = getNow() +"("+ userLogin.UserInfo().userCode + ")";
                m.id = int.Parse(dataId);
                oper = new OperateModel();
                oper.Data = m;
                oper.Conditions = "id";
                oper.Types = OperateModel.OperateType.Edit;
                rsl = cmd.Edit(oper);
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }


    }
}
